Skip to content

Commit

Permalink
Suppress testing SemIR in int builtin tests. (#4748)
Browse files Browse the repository at this point in the history
Add `EXTRA-ARGS:` support to file_test, to add arguments without
overriding the default arguments. Use `EXTRA-ARGS: --no-dump-sem-ir` to
turn off SemIR dumping and thus SemIR testing in the int builtin tests,
which validate correct behavior through diagnostics instead.

This doesn't get us any closer to supporting more targeted SemIR dumping
/ testing, but this seems to be a generally useful feature anyway. Most
existing
tests using `ARGS` have been switched over to using `EXTRA-ARGS`.

Requested in review of #4716.
  • Loading branch information
zygoloid authored Dec 31, 2024
1 parent 89df777 commit d416683
Show file tree
Hide file tree
Showing 50 changed files with 689 additions and 12,261 deletions.
10 changes: 10 additions & 0 deletions testing/file_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ Supported comment markers are:
ARGS can be specified at most once. If not provided, the FileTestBase child
is responsible for providing default arguments.
- ```
// EXTRA-ARGS: <arguments>
```
Same as `ARGS`, including substitution behavior, but appends to the default
argument list instead of replacing it.
`EXTRA-ARGS` can be specified at most once, and a test cannot specify both
`ARGS` and `EXTRA-ARGS`.
- ```
// SET-CAPTURE-CONSOLE-OUTPUT
```
Expand Down
23 changes: 16 additions & 7 deletions testing/file_test/file_test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ auto FileTestBase::ProcessTestFileAndRun(TestContext& context)
// Process arguments.
if (context.test_args.empty()) {
context.test_args = GetDefaultArgs();
context.test_args.append(context.extra_args);
}
CARBON_RETURN_IF_ERROR(
DoArgReplacements(context.test_args, context.test_files));
Expand Down Expand Up @@ -767,24 +768,31 @@ static auto TryConsumeCheck(
return true;
}

// Processes ARGS lines when found. Returns true if the line is consumed.
// Processes ARGS and EXTRA-ARGS lines when found. Returns true if the line is
// consumed.
static auto TryConsumeArgs(llvm::StringRef line, llvm::StringRef line_trimmed,
llvm::SmallVector<std::string>* args)
llvm::SmallVector<std::string>* args,
llvm::SmallVector<std::string>* extra_args)
-> ErrorOr<bool> {
if (!line_trimmed.consume_front("// ARGS: ")) {
llvm::SmallVector<std::string>* arg_list = nullptr;
if (line_trimmed.consume_front("// ARGS: ")) {
arg_list = args;
} else if (line_trimmed.consume_front("// EXTRA-ARGS: ")) {
arg_list = extra_args;
} else {
return false;
}

if (!args->empty()) {
return ErrorBuilder() << "ARGS was specified multiple times: "
if (!args->empty() || !extra_args->empty()) {
return ErrorBuilder() << "ARGS / EXTRA-ARGS specified multiple times: "
<< line.str();
}

// Split the line into arguments.
std::pair<llvm::StringRef, llvm::StringRef> cursor =
llvm::getToken(line_trimmed);
while (!cursor.first.empty()) {
args->push_back(std::string(cursor.first));
arg_list->push_back(std::string(cursor.first));
cursor = llvm::getToken(cursor.second);
}

Expand Down Expand Up @@ -884,7 +892,8 @@ auto FileTestBase::ProcessTestFile(TestContext& context) -> ErrorOr<Success> {
FileTestLine(split.file_index, line_index, line));

CARBON_ASSIGN_OR_RETURN(
is_consumed, TryConsumeArgs(line, line_trimmed, &context.test_args));
is_consumed, TryConsumeArgs(line, line_trimmed, &context.test_args,
&context.extra_args));
if (is_consumed) {
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions testing/file_test/file_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class FileTestBase : public testing::Test {
// Arguments for the test, generated from ARGS.
llvm::SmallVector<std::string> test_args;

// Extra arguments for the test, generated from EXTRA-ARGS. Unlike ARGS,
// setting EXTRA-ARGS does not suppress the default arguments.
llvm::SmallVector<std::string> extra_args;

// Files in the test, generated by content and splits.
llvm::SmallVector<TestFile> test_files;

Expand Down
34 changes: 15 additions & 19 deletions toolchain/check/testdata/basics/no_prelude/raw_identifier.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// ARGS: compile --no-prelude-import --phase=check --dump-sem-ir %s
//
// Check that the command-line flag to dump textual IR works.
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/basics/no_prelude/raw_identifier.carbon
Expand Down Expand Up @@ -48,12 +44,12 @@ fn C(r#if: ()) -> () {
// CHECK:STDOUT: %return.patt: %empty_tuple.type = return_slot_pattern
// CHECK:STDOUT: %return.param_patt: %empty_tuple.type = out_param_pattern %return.patt, runtime_param1
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc15_17.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_17.2: type = converted %.loc15_17.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc11_17.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc11_17.2: type = converted %.loc11_17.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc15_10.1: type = splice_block %.loc15_10.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_10.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_10.3: type = converted %.loc15_10.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc11_10.1: type = splice_block %.loc11_10.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc11_10.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc11_10.3: type = converted %.loc11_10.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
// CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param1
Expand All @@ -65,12 +61,12 @@ fn C(r#if: ()) -> () {
// CHECK:STDOUT: %return.patt: %empty_tuple.type = return_slot_pattern
// CHECK:STDOUT: %return.param_patt: %empty_tuple.type = out_param_pattern %return.patt, runtime_param1
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc19_19.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc19_19.2: type = converted %.loc19_19.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc15_19.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_19.2: type = converted %.loc15_19.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc19_12.1: type = splice_block %.loc19_12.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc19_12.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc19_12.3: type = converted %.loc19_12.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc15_12.1: type = splice_block %.loc15_12.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_12.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_12.3: type = converted %.loc15_12.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
// CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param1
Expand All @@ -82,12 +78,12 @@ fn C(r#if: ()) -> () {
// CHECK:STDOUT: %return.patt: %empty_tuple.type = return_slot_pattern
// CHECK:STDOUT: %return.param_patt: %empty_tuple.type = out_param_pattern %return.patt, runtime_param1
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc23_20.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc23_20.2: type = converted %.loc23_20.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc19_20.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc19_20.2: type = converted %.loc19_20.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %if.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc23_13.1: type = splice_block %.loc23_13.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc23_13.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc23_13.3: type = converted %.loc23_13.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc19_13.1: type = splice_block %.loc19_13.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc19_13.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc19_13.3: type = converted %.loc19_13.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %if: %empty_tuple.type = bind_name r#if, %if.param
// CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param1
Expand Down
Loading

0 comments on commit d416683

Please sign in to comment.