Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1fec40fc9e | |||
| 2ebf193695 |
@@ -75,7 +75,7 @@
|
|||||||
},
|
},
|
||||||
"block-keywords": {
|
"block-keywords": {
|
||||||
"name": "variable.parameter.jdg",
|
"name": "variable.parameter.jdg",
|
||||||
"match": "\\b(?:weight|scoring|stdin|stdout|stderr|args|exitCode|input|dirs)\\b"
|
"match": "\\b(?:weight|scoring|stdin|stdout|stderr|args|args_file|exitCode|input|dirs|stage)\\b"
|
||||||
},
|
},
|
||||||
"matcher-keywords": {
|
"matcher-keywords": {
|
||||||
"name": "support.function.jdg",
|
"name": "support.function.jdg",
|
||||||
|
|||||||
@@ -48,6 +48,8 @@
|
|||||||
"input"
|
"input"
|
||||||
"output"
|
"output"
|
||||||
"dirs"
|
"dirs"
|
||||||
|
"stage"
|
||||||
|
"args_file"
|
||||||
] @property
|
] @property
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -86,6 +86,13 @@ func writeBuildText(w io.Writer, b *runner.BuildRun, multi bool) {
|
|||||||
fmt.Fprintf(w, "│ %s\n", line)
|
fmt.Fprintf(w, "│ %s\n", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tr.Status != runner.StatusPass && strings.TrimSpace(tr.ActualStderr) != "" {
|
||||||
|
fmt.Fprintf(w, "│ ── stderr ──\n")
|
||||||
|
for _, line := range clampLines(tr.ActualStderr, 10) {
|
||||||
|
fmt.Fprintf(w, "│ %s\n", line)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "└─\n")
|
fmt.Fprintf(w, "└─\n")
|
||||||
}
|
}
|
||||||
@@ -265,6 +272,18 @@ func extractTotalScore(data []byte) (float64, error) {
|
|||||||
return header.TotalScore, nil
|
return header.TotalScore, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clampLines returns up to max lines of s (trailing newline ignored), appending
|
||||||
|
// a truncation note when more lines were omitted.
|
||||||
|
func clampLines(s string, max int) []string {
|
||||||
|
s = strings.TrimRight(s, "\n")
|
||||||
|
lines := strings.Split(s, "\n")
|
||||||
|
if len(lines) <= max {
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
out := append([]string{}, lines[:max]...)
|
||||||
|
return append(out, fmt.Sprintf("... (%d more lines)", len(lines)-max))
|
||||||
|
}
|
||||||
|
|
||||||
func humanBytes(n int64) string {
|
func humanBytes(n int64) string {
|
||||||
const (
|
const (
|
||||||
KiB = 1024
|
KiB = 1024
|
||||||
|
|||||||
@@ -407,6 +407,8 @@ func (r *Runner) runGroup(g *dsl.Group) *GroupResult {
|
|||||||
t.Wrapper = g.Wrapper
|
t.Wrapper = g.Wrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.normalizeExpectations(t)
|
||||||
|
|
||||||
tr := r.runTest(t)
|
tr := r.runTest(t)
|
||||||
gr.Tests = append(gr.Tests, tr)
|
gr.Tests = append(gr.Tests, tr)
|
||||||
if tr.Status == StatusPass {
|
if tr.Status == StatusPass {
|
||||||
@@ -609,6 +611,40 @@ func buildExecCmd(ctx context.Context, wrapper, binary string, args []string) *e
|
|||||||
return exec.CommandContext(ctx, full[0], full[1:]...)
|
return exec.CommandContext(ctx, full[0], full[1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normalizeExpectations applies the suite's CRLF/whitespace normalization to a
|
||||||
|
// test's *expected* values, mirroring what normalizeOutput does to the actual
|
||||||
|
// output. Without this, an expected value loaded from disk on Windows (e.g. an
|
||||||
|
// answer file checked out with CRLF) would never match LF-normalized actual
|
||||||
|
// output even with normalize_crlf enabled.
|
||||||
|
func (r *Runner) normalizeExpectations(t *dsl.Test) {
|
||||||
|
if !r.file.NormalizeCRLF && !r.file.TrimTrailingWS {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Stdout = r.normalizeMatcher(t.Stdout)
|
||||||
|
t.Stderr = r.normalizeMatcher(t.Stderr)
|
||||||
|
for k, v := range t.OutFiles {
|
||||||
|
t.OutFiles[k] = normalizeOutput(v, r.file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// normalizeMatcher normalizes the expected payload of the matchers that compare
|
||||||
|
// whole-output text. Regex and numeric matchers are left untouched: their
|
||||||
|
// patterns are authored deliberately and must not be rewritten.
|
||||||
|
func (r *Runner) normalizeMatcher(m dsl.Matcher) dsl.Matcher {
|
||||||
|
switch x := m.(type) {
|
||||||
|
case dsl.ExactMatcher:
|
||||||
|
return dsl.ExactMatcher{Value: normalizeOutput(x.Value, r.file)}
|
||||||
|
case dsl.AnyOrderMatcher:
|
||||||
|
lines := make([]string, len(x.Lines))
|
||||||
|
for i, l := range x.Lines {
|
||||||
|
lines[i] = normalizeOutput(l, r.file)
|
||||||
|
}
|
||||||
|
return dsl.AnyOrderMatcher{Lines: lines}
|
||||||
|
default:
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func normalizeOutput(s string, f *dsl.File) string {
|
func normalizeOutput(s string, f *dsl.File) string {
|
||||||
if f.NormalizeCRLF {
|
if f.NormalizeCRLF {
|
||||||
s = strings.ReplaceAll(s, "\r\n", "\n")
|
s = strings.ReplaceAll(s, "\r\n", "\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user