Skip to content

Commit 899db28

Browse files
authored
acc: support logging from acceptance tests (#3789)
## Changes If you output to file with prefix "LOG", it gets logged to test log. ## Why Debugging acceptance tests without messing expected output. ## Tests New self test.
1 parent b137cb2 commit 899db28

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

acceptance/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ For more complex tests one can also use:
1818
- `trace` helper: prints the arguments before executing the command.
1919
- custom output files: redirect output to custom file (it must start with `out`), e.g. `$CLI bundle validate > out.txt 2> out.error.txt`.
2020

21-
See [selftest](./selftest) for a toy test.
21+
Any file starting with "LOG" will be logged to test log (visible with go test -v).
22+
23+
See [selftest](./selftest) for more examples.
2224

2325
## Running acceptance tests on Windows
2426

acceptance/acceptance_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,17 @@ func runTest(t *testing.T,
714714
if config.CompiledIgnoreObject.MatchesPath(relPath) {
715715
continue
716716
}
717+
if strings.HasPrefix(filepath.Base(relPath), "LOG") {
718+
prefix := relPath + ": "
719+
messages := testutil.ReadFile(t, filepath.Join(tmpDir, relPath))
720+
messages = strings.TrimRight(messages, "\r\n \t")
721+
messages = prefix + strings.ReplaceAll(messages, "\n", "\n"+prefix)
722+
if strings.Contains(messages, "\n") {
723+
messages = "\n" + messages
724+
}
725+
t.Log(messages)
726+
continue
727+
}
717728
unexpected = append(unexpected, relPath)
718729
if strings.HasPrefix(relPath, "out") {
719730
// We have a new file starting with "out"

acceptance/selftest/log/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/selftest/log/output.txt

Whitespace-only changes.

acceptance/selftest/log/script

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# If logs are visible (go test -v), this will produce this:
2+
# acceptance_test.go:725:
3+
# LOG: main log
4+
# LOG: no replacements: 123456789
5+
# LOG: Tue Oct 21 12:07:45 CEST 2025
6+
# acceptance_test.go:725: subdir/LOG.extra: extra log
7+
8+
echo "main log" >> LOG
9+
echo "no replacements: 123456789" >> LOG
10+
date >> LOG
11+
12+
mkdir subdir
13+
echo "extra log" >> subdir/LOG.extra

0 commit comments

Comments
 (0)