diff options
| author | Ethan Reesor <ethan.reesor@gmail.com> | 2024-11-16 08:54:45 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-03-09 11:02:12 -0700 |
| commit | f5e3332108dd73166a1cbe35bfebe8bf99386019 (patch) | |
| tree | 438b64c8525f6a8cc2aa03d0710f15ce70455d8c /src/cmd/internal/script/scripttest/scripttest.go | |
| parent | d82eb907f3ef66e99d1ef08c0b34ffffbd49de5e (diff) | |
| download | go-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/script/scripttest/scripttest.go')
| -rw-r--r-- | src/cmd/internal/script/scripttest/scripttest.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/cmd/internal/script/scripttest/scripttest.go b/src/cmd/internal/script/scripttest/scripttest.go index 349201fd18..418b063b28 100644 --- a/src/cmd/internal/script/scripttest/scripttest.go +++ b/src/cmd/internal/script/scripttest/scripttest.go @@ -89,7 +89,7 @@ func Run(t testing.TB, e *script.Engine, s *script.State, filename string, testS return e.Execute(s, filename, bufio.NewReader(testScript), log) }() - if skip, ok := errors.AsType[skipError](err); ok { + if skip, ok := errors.AsType[SkipError](err); ok { if skip.msg == "" { t.Skip("SKIP") } else { @@ -113,17 +113,18 @@ func Skip() script.Cmd { return nil, script.ErrUsage } if len(args) == 0 { - return nil, skipError{""} + return nil, SkipError{""} } - return nil, skipError{args[0]} + return nil, SkipError{args[0]} }) } -type skipError struct { +// SkipError is returned by a script test that executes the [Skip] command. +type SkipError struct { msg string } -func (s skipError) Error() string { +func (s SkipError) Error() string { if s.msg == "" { return "skip" } |
