feat: support hide output in diff parser
All checks were successful
build / build (push) Successful in 1m53s
build / trigger-build-image (push) Successful in 6s

This commit is contained in:
张泊明518370910136 2024-10-08 01:57:00 -04:00
parent 3f9ec1a71d
commit d3ffb03482
GPG Key ID: D47306D7062CDA9D

View File

@ -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,
)
}
} }
} }
} }