feat: support hide output in diff parser
This commit is contained in:
parent
3f9ec1a71d
commit
d3ffb03482
|
@ -28,6 +28,7 @@ type Conf struct {
|
||||||
FileName string
|
FileName string
|
||||||
AnswerPath string
|
AnswerPath string
|
||||||
IgnoreWhitespace bool
|
IgnoreWhitespace bool
|
||||||
|
AlwaysHide bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,22 +69,29 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
"actual", result.Files[output.FileName],
|
"actual", result.Files[output.FileName],
|
||||||
"answer", string(answer))
|
"answer", string(answer))
|
||||||
// If no difference, assign score
|
// If no difference, assign score
|
||||||
if compareChars(string(answer), result.Files[output.FileName], output.IgnoreWhitespace) {
|
if compareChars(string(answer), result.Files[output.FileName],
|
||||||
|
output.IgnoreWhitespace) {
|
||||||
score += output.Score
|
score += output.Score
|
||||||
} else {
|
} else {
|
||||||
// Convert answer to string and split by lines
|
comment += fmt.Sprintf("Difference found in `%s`.\n",
|
||||||
stdoutLines := strings.Split(string(answer), "\n")
|
output.FileName)
|
||||||
resultLines := strings.Split(result.Files[output.FileName], "\n")
|
if !output.AlwaysHide {
|
||||||
|
// Convert answer to string and split by lines
|
||||||
|
stdoutLines := strings.Split(string(answer), "\n")
|
||||||
|
resultLines := strings.Split(
|
||||||
|
result.Files[output.FileName], "\n")
|
||||||
|
|
||||||
// Generate Myers diff
|
// Generate Myers diff
|
||||||
diffOps := myersDiff(stdoutLines, resultLines)
|
diffOps := myersDiff(stdoutLines, resultLines)
|
||||||
|
|
||||||
// Generate diff block with surrounding context
|
// Generate diff block with surrounding context
|
||||||
diffOutput := generateDiffWithContext(stdoutLines, resultLines, diffOps)
|
diffOutput := generateDiffWithContext(
|
||||||
comment += fmt.Sprintf(
|
stdoutLines, resultLines, diffOps)
|
||||||
"difference found in %s:\n```diff\n%s```\n",
|
comment += fmt.Sprintf(
|
||||||
output.FileName, diffOutput,
|
"```diff\n%s```\n",
|
||||||
)
|
diffOutput,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user