diff --git a/testing/file_test/README.md b/testing/file_test/README.md index 0fdeba4a3ee9..93067b5548a4 100644 --- a/testing/file_test/README.md +++ b/testing/file_test/README.md @@ -217,6 +217,8 @@ Supported comment markers are: - `// ARGS` - `// EXTRA-ARGS` + - Included `EXTRA-ARGS` will come before `EXTRA-ARGS` in the main test + file. - `// INCLUDE-FILE` - `// --- ` diff --git a/testing/file_test/test_file.cpp b/testing/file_test/test_file.cpp index ad9ac1a44bfc..11c4bb4318c5 100644 --- a/testing/file_test/test_file.cpp +++ b/testing/file_test/test_file.cpp @@ -797,10 +797,14 @@ auto ProcessTestFile(llvm::StringRef test_name, bool running_autoupdate) // (recursively). llvm::SmallVector include_files; + // Store the main file's `EXTRA-ARGS` so that they can be put after any that + // come from `INCLUDE-FILE`. + llvm::SmallVector main_extra_args; + // Process the main file. CARBON_RETURN_IF_ERROR(ProcessFileContent( test_name, test_file.input_content, running_autoupdate, &test_file, - &found_autoupdate, test_file.test_args, test_file.extra_args, + &found_autoupdate, test_file.test_args, main_extra_args, test_file.file_splits, include_files)); if (!found_autoupdate) { @@ -859,6 +863,9 @@ auto ProcessTestFile(llvm::StringRef test_name, bool running_autoupdate) } } + // Copy over `EXTRA-ARGS` from the main file (after includes). + test_file.extra_args.append(main_extra_args); + return std::move(test_file); } diff --git a/testing/file_test/testdata/include_extra_args.carbon b/testing/file_test/testdata/include_extra_args.carbon index ce6bff541d42..190c2c2df439 100644 --- a/testing/file_test/testdata/include_extra_args.carbon +++ b/testing/file_test/testdata/include_extra_args.carbon @@ -11,4 +11,4 @@ // TIP: To dump output, run: // TIP: bazel run //testing/file_test:file_test_base_test -- --dump_output --file_tests=testing/file_test/testdata/include_extra_args.carbon -// CHECK:STDOUT: 6 args: `default_args`, `include_extra_args.carbon`, `include_files/extra_args.carbon`, `foo`, `bar`, `baz` +// CHECK:STDOUT: 6 args: `default_args`, `include_extra_args.carbon`, `include_files/extra_args.carbon`, `bar`, `baz`, `foo`