aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/test2json/testdata
diff options
context:
space:
mode:
authorEthan Reesor <ethan.reesor@gmail.com>2024-11-16 08:54:45 -0700
committerGopher Robot <gobot@golang.org>2026-03-09 11:02:12 -0700
commitf5e3332108dd73166a1cbe35bfebe8bf99386019 (patch)
tree438b64c8525f6a8cc2aa03d0710f15ce70455d8c /src/cmd/internal/test2json/testdata
parentd82eb907f3ef66e99d1ef08c0b34ffffbd49de5e (diff)
downloadgo-f5e3332108dd73166a1cbe35bfebe8bf99386019.tar.xz
cmd/internal/test2json: generate and validate test artifacts
Adds a mechanism for generating test2json test artifacts from and validating them against a real test. If a .test file has a corresponding .src file, TestGolden will now treat the .src file as a script test, executing it and verifying that the output matches the contents of the .test file. Running TestGolden with the -update flag will also regenerate .test files if they have a corresponding .src file. Capturing the output of the script test in this way required making minor changes to cmd/internal/script/scripttest. This was motivated by CL 601535 (golang/go#62728). Specifically, testing that CL required adding src/cmd/internal/test2json/testdata/frameescape.test which has a multitude of non-printing characters and thus must be generated by executing `go test`. Using a script test to generate the test file is more reliable than doing it by hand. Change-Id: I60456700e37e21a42d0514be2ce86dc6df2bccb0 Reviewed-on: https://go-review.googlesource.com/c/go/+/628615 Reviewed-by: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/cmd/internal/test2json/testdata')
-rw-r--r--src/cmd/internal/test2json/testdata/README.md11
-rw-r--r--src/cmd/internal/test2json/testdata/frameescape.src24
-rw-r--r--src/cmd/internal/test2json/testdata/multiline-error.src15
3 files changed, 50 insertions, 0 deletions
diff --git a/src/cmd/internal/test2json/testdata/README.md b/src/cmd/internal/test2json/testdata/README.md
new file mode 100644
index 0000000000..e86c88f51c
--- /dev/null
+++ b/src/cmd/internal/test2json/testdata/README.md
@@ -0,0 +1,11 @@
+# test2json test artifacts
+
+This directory contains test artifacts for `TestGolden` in
+[test2json_test.go](../test2json_test.go). For each set of `<test>.*` files:
+
+- If `<test>.src` is present, TestGolden executes it as a script test and verifies
+ that the output matches `<test>.test`. This verifies that the testing package
+ produces the output expected by test2json.
+- TestGolden reads `<test>.test` and processes it with a `Converter`, verifying
+ that the output matches `<test>.json`.This verifies that test2json produces
+ the expected output events. \ No newline at end of file
diff --git a/src/cmd/internal/test2json/testdata/frameescape.src b/src/cmd/internal/test2json/testdata/frameescape.src
new file mode 100644
index 0000000000..4bad6dac77
--- /dev/null
+++ b/src/cmd/internal/test2json/testdata/frameescape.src
@@ -0,0 +1,24 @@
+! go test -v=test2json
+
+stdout '=== RUN TestAscii'
+
+-- go.mod --
+module p
+
+-- x_test.go --
+package p
+
+import "testing"
+
+func TestAscii(t *testing.T) {
+ t.Run("Log", func(t *testing.T) {
+ for i := rune(0); i < 0x80; i++ {
+ t.Log(string(i))
+ }
+ })
+ t.Run("Error", func(t *testing.T) {
+ for i := rune(0); i < 0x80; i++ {
+ t.Error(string(i))
+ }
+ })
+}
diff --git a/src/cmd/internal/test2json/testdata/multiline-error.src b/src/cmd/internal/test2json/testdata/multiline-error.src
new file mode 100644
index 0000000000..a09570bd82
--- /dev/null
+++ b/src/cmd/internal/test2json/testdata/multiline-error.src
@@ -0,0 +1,15 @@
+! go test -v=test2json
+
+stdout '=== RUN Test'
+
+-- go.mod --
+module p
+
+-- x_test.go --
+package p
+
+import "testing"
+
+func Test(t *testing.T) {
+ t.Error("Error1\nError2\r")
+}