Make the 'library' lines in tests use a substitution. (#4278)

This opens the door for replacing all `library ...` lines in toolchain
test files with `library "[[@TEST_NAME]]";`. That's technically more
typing in a lot of cases, but OTOH means we can just do some copy-paste
boilerplate and stop carefully writing library names.

Also cleans up the test setup, because it's getting messy. I'm trying to
make it easier to see the divisions of tests and the output associated
with them. StringSwitch looked like a way to do this, with a few edits
to make it work nicely.
This commit is contained in:
Jon Ross-Perkins
2024-09-10 20:24:11 +00:00
committed by GitHub
parent 5806d8385d
commit 2e299f5fc4
7 changed files with 341 additions and 128 deletions
+3 -1
View File
@@ -8,4 +8,6 @@
// TIP: To dump output, run:
// TIP: bazel run //testing/file_test:file_test_base_test -- --dump_output --file_tests=testing/file_test/testdata/not_split.carbon
// CHECK:STDOUT: 2 args: `default_args`, `not_split.carbon`
// CHECK:STDOUT: not_split.carbon:[[@LINE-10]]: starts with "// Part of the Carbon Language project, ", length 11 lines
not split
// CHECK:STDOUT: not_split.carbon:[[@LINE-1]]: not split
+13
View File
@@ -0,0 +1,13 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //testing/file_test:file_test_base_test --test_arg=--file_tests=testing/file_test/testdata/replace_content.carbon
// TIP: To dump output, run:
// TIP: bazel run //testing/file_test:file_test_base_test -- --dump_output --file_tests=testing/file_test/testdata/replace_content.carbon
// CHECK:STDOUT: 2 args: `default_args`, `replace_content.carbon`
library "[[@TEST_NAME]]";
// CHECK:STDOUT: replace_content.carbon:[[@LINE-1]]: library "replace_content";
+35
View File
@@ -0,0 +1,35 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //testing/file_test:file_test_base_test --test_arg=--file_tests=testing/file_test/testdata/replace_split_content.carbon
// TIP: To dump output, run:
// TIP: bazel run //testing/file_test:file_test_base_test -- --dump_output --file_tests=testing/file_test/testdata/replace_split_content.carbon
// CHECK:STDOUT: 6 args: `default_args`, `a.carbon`, `b.impl.carbon`, `todo_c.carbon`, `todo_fail_d.carbon`, `triplicate.carbon`
// --- a.carbon
library "[[@TEST_NAME]]";
// CHECK:STDOUT: a.carbon:[[@LINE-1]]: library "a";
// --- b.impl.carbon
library "[[@TEST_NAME]]";
// CHECK:STDOUT: b.impl.carbon:[[@LINE-1]]: library "b";
// --- todo_c.carbon
library "[[@TEST_NAME]]";
// CHECK:STDOUT: todo_c.carbon:[[@LINE-1]]: library "c";
// --- todo_fail_d.carbon
library "[[@TEST_NAME]]";
// CHECK:STDOUT: todo_fail_d.carbon:[[@LINE-1]]: library "d";
// --- triplicate.carbon
[[@TEST_NAME]][[@TEST_NAME]][[@TEST_NAME]]
// CHECK:STDOUT: triplicate.carbon:[[@LINE-1]]: triplicatetriplicatetriplicate
+3 -2
View File
@@ -11,8 +11,9 @@
// --- a.carbon
aaa
// CHECK:STDOUT: a.carbon:[[@LINE-1]]: starts with "aaa\n// CHECK:STDOUT: a.carbon:{{\[\[}}@LINE-1]", length 3 lines
// CHECK:STDOUT: a.carbon:[[@LINE-1]]: aaa
// --- b.carbon
bbb
// CHECK:STDOUT: b.carbon:[[@LINE-1]]: starts with "bbb\n// CHECK:STDOUT: b.carbon:{{\[\[}}@LINE-1]", length 2 lines
// CHECK:STDOUT: b.carbon:[[@LINE-1]]: bbb