Skip to content

Commit 0963848

Browse files
authored
acc: add TESTLOG feature (#4175)
If output lines are prefixed with "TESTLOG: " they will be logged but not recorded in the output. This is similar to LOG* feature (#3789) but it logs lines are they come which more useful for debugging log-running tests.
1 parent 21129d6 commit 0963848

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

acceptance/acceptance_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ var (
6060
// Also disables parallelism in tests.
6161
var InprocessMode bool
6262

63+
// lines with this prefix are not recorded in output.txt but logged instead
64+
const TestLogPrefix = "TESTLOG: "
65+
6366
func init() {
6467
flag.BoolVar(&InprocessMode, "inprocess", false, "Run CLI in the same process as test (for debugging)")
6568
flag.BoolVar(&KeepTmp, "keeptmp", false, "Do not delete TMP directory after run")
@@ -1245,14 +1248,20 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) (string, e
12451248
if tail {
12461249
msg := strings.TrimRight(line, "\n")
12471250
if len(msg) > 0 {
1248-
d := time.Since(start)
1249-
t.Logf("%2d.%03d %s", d/time.Second, (d%time.Second)/time.Millisecond, msg)
1251+
logWithDurationSince(t, start, msg)
12501252
}
12511253
}
12521254
if len(line) > 0 {
12531255
mostRecentLine = line
1254-
_, err = out.WriteString(line)
1255-
require.NoError(t, err)
1256+
if strings.HasPrefix(line, TestLogPrefix) {
1257+
// if tail is true, we already logged it above
1258+
if !tail {
1259+
logWithDurationSince(t, start, strings.TrimRight(line, "\n"))
1260+
}
1261+
} else {
1262+
_, err = out.WriteString(line)
1263+
require.NoError(t, err)
1264+
}
12561265
}
12571266
if err == io.EOF {
12581267
break
@@ -1269,6 +1278,11 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) (string, e
12691278
return skipReason, <-processErrCh
12701279
}
12711280

1281+
func logWithDurationSince(t *testing.T, start time.Time, msg string) {
1282+
d := time.Since(start)
1283+
t.Logf("%2d.%03d %s", d/time.Second, (d%time.Second)/time.Millisecond, msg)
1284+
}
1285+
12721286
func getCloudEnvBase(cloudEnv string) string {
12731287
switch cloudEnv {
12741288
// no idea why, but

acceptance/selftest/testlog/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/testlog/output.txt

Whitespace-only changes.

acceptance/selftest/testlog/script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "TESTLOG: this is logged, not saved to output.txt"

0 commit comments

Comments
 (0)