Skip to content

Commit ddb3c7a

Browse files
committed
refactor: improve file contents logging in test utilities
Modify logReadableFileContents to dynamically update logger's secondary prefix with test-specific .lox file name and simplify logging output
1 parent 2e206aa commit ddb3c7a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/test_cases/utils.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88

99
"github.com/codecrafters-io/tester-utils/logger"
10-
"github.com/fatih/color"
1110
)
1211

1312
func createTempFileWithContents(contents string) (string, error) {
@@ -48,8 +47,14 @@ func logReadableFileContents(logger *logger.Logger, fileContents string) {
4847
printableFileContents = regex1.ReplaceAllString(printableFileContents, "<|SPACE|>")
4948
printableFileContents = regex2.ReplaceAllString(printableFileContents, "<|SPACE|>")
5049

50+
// This is of the form "test-N"
51+
oldPrefix := logger.GetSecondaryPrefix()
52+
testNumber := strings.TrimPrefix(oldPrefix, "test-")
53+
logger.UpdateSecondaryPrefix(fmt.Sprintf("test-%s.lox", testNumber))
54+
defer logger.UpdateSecondaryPrefix(oldPrefix)
55+
5156
for _, line := range strings.Split(printableFileContents, "\n") {
52-
logger.Plainf(color.YellowString("[test.lox]") + " " + line)
57+
logger.Plainf(line)
5358
}
5459
}
5560

0 commit comments

Comments
 (0)