Skip to content

Commit

Permalink
Test trailing space in explanation and errors in log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Jul 14, 2024
1 parent 29eb119 commit 47d164f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
12 changes: 12 additions & 0 deletions v23/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,18 @@ func (t *Tester) ExpectAssert(action func()) {
t.Check(action, check.Panics, "Pkglint internal error")
}

// ExpectAssert runs the given action and expects that this action calls
// assertf, failing with the given message.
//
// Usage:
//
// t.ExpectAssertf(
// func() { /* do something that panics */ },
// "expected message")
func (t *Tester) ExpectAssertf(action func(), msg string) {
t.Check(action, check.Panics, "Pkglint internal error: "+msg)
}

// ExpectDiagnosticsAutofix first runs the given action with -Wall, and
// then another time with -Wall --autofix.
//
Expand Down
7 changes: 3 additions & 4 deletions v23/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ func (l *Logger) Diag(line *Line, level *LogLevel, format string, args ...interf
if G.Testing {
for _, arg := range args {
switch arg.(type) {
case int, string:
case RelPath:
case int, string, RelPath:
case CurrPath:
// All paths in diagnostics must be relative to the line.
// To achieve that, call line.Rel(currPath).
_ = arg.(RelPath)
case error:
// TODO: errors do not belong in diagnostics,
// they belong in normal error messages.
// To log an error, use TechFatalF instead.
_ = arg.(string)
default:
_ = arg.(string)
}
Expand Down
18 changes: 18 additions & 0 deletions v23/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ func (s *Suite) Test_Logger_Explain__line_wrapped_temporary_directory(c *check.C
"")
}

func (s *Suite) Test_Logger_Explain__trailing_space(c *check.C) {
t := s.Init(c)

t.SetUpCommandLine("--explain")
filename := t.File("filename.mk")
mkline := t.NewMkLine(filename, 123, "")

mkline.Notef("Just a note to get the below explanation.")
t.ExpectAssertf(
func() {
G.Logger.Explain(
"Trailing space. ")
},
"Explanation \"Trailing space. \" must not have trailing space")
t.CheckOutputLines(
"NOTE: ~/filename.mk:123: Just a note to get the below explanation.")
}

// Diag filters duplicate messages, unlike Logf.
func (s *Suite) Test_Logger_Diag__duplicates(c *check.C) {
t := s.Init(c)
Expand Down
2 changes: 1 addition & 1 deletion v23/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ func (ck *ShellLineChecker) CheckShellCommand(shellcmd string, pSetE *bool, time
return
}
if err != nil {
line.Warnf("Pkglint ShellLine.CheckShellCommand: %s", err)
line.Warnf("Pkglint ShellLine.CheckShellCommand: %s", err.Error())
return
}

Expand Down

0 comments on commit 47d164f

Please sign in to comment.