Skip to content

Commit 64c31a6

Browse files
authored
Adjust ordering of EXTRA-ARGS to allow tests to override includes (#5870)
1 parent 3d6395b commit 64c31a6

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

testing/file_test/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ Supported comment markers are:
217217
218218
- `// ARGS`
219219
- `// EXTRA-ARGS`
220+
- Included `EXTRA-ARGS` will come before `EXTRA-ARGS` in the main test
221+
file.
220222
- `// INCLUDE-FILE`
221223
- `// --- <filename>`
222224

testing/file_test/test_file.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,14 @@ auto ProcessTestFile(llvm::StringRef test_name, bool running_autoupdate)
797797
// (recursively).
798798
llvm::SmallVector<std::string> include_files;
799799

800+
// Store the main file's `EXTRA-ARGS` so that they can be put after any that
801+
// come from `INCLUDE-FILE`.
802+
llvm::SmallVector<std::string> main_extra_args;
803+
800804
// Process the main file.
801805
CARBON_RETURN_IF_ERROR(ProcessFileContent(
802806
test_name, test_file.input_content, running_autoupdate, &test_file,
803-
&found_autoupdate, test_file.test_args, test_file.extra_args,
807+
&found_autoupdate, test_file.test_args, main_extra_args,
804808
test_file.file_splits, include_files));
805809

806810
if (!found_autoupdate) {
@@ -859,6 +863,9 @@ auto ProcessTestFile(llvm::StringRef test_name, bool running_autoupdate)
859863
}
860864
}
861865

866+
// Copy over `EXTRA-ARGS` from the main file (after includes).
867+
test_file.extra_args.append(main_extra_args);
868+
862869
return std::move(test_file);
863870
}
864871

testing/file_test/testdata/include_extra_args.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
// TIP: To dump output, run:
1212
// TIP: bazel run //testing/file_test:file_test_base_test -- --dump_output --file_tests=testing/file_test/testdata/include_extra_args.carbon
1313

14-
// CHECK:STDOUT: 6 args: `default_args`, `include_extra_args.carbon`, `include_files/extra_args.carbon`, `foo`, `bar`, `baz`
14+
// CHECK:STDOUT: 6 args: `default_args`, `include_extra_args.carbon`, `include_files/extra_args.carbon`, `bar`, `baz`, `foo`

0 commit comments

Comments
 (0)