feat: diff parser with multiple outputs in one case
This commit is contained in:
parent
eac7a62ebe
commit
52491478a4
|
@ -1 +1 @@
|
|||
Subproject commit 2593e79505a93042d308c5fc355dba671dd4fdba
|
||||
Subproject commit 4e5fab93e5a0ce67c8f40fef1e8f4cab7018fc5d
|
|
@ -1 +1 @@
|
|||
Subproject commit 638e9f661092d39daaf6e1ffc8ba5998fc56c96a
|
||||
Subproject commit 1512cb5f20473a598d7504a08dacff3d6406b983
|
|
@ -1 +1 @@
|
|||
Subproject commit d8d66fb5b47b5e79e08532da31d397a5d461f087
|
||||
Subproject commit af990327ab095c22a383448ad70d915f8d10490b
|
|
@ -1 +1 @@
|
|||
Subproject commit fc774118794a5c5ec0b88863ba6c8492e5b13f89
|
||||
Subproject commit ac7a2fc912fb51af156cd4babb7e72148ebe1c14
|
|
@ -20,9 +20,12 @@ const (
|
|||
|
||||
type Conf struct {
|
||||
Cases []struct {
|
||||
Score int
|
||||
StdoutPath string
|
||||
IgnoreWhitespace bool
|
||||
Outputs []struct {
|
||||
Score int
|
||||
FileName string
|
||||
AnswerPath string
|
||||
IgnoreWhitespace bool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,35 +46,31 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
|
|||
for i, caseConf := range conf.Cases {
|
||||
result := results[i]
|
||||
score := 0
|
||||
var comment string
|
||||
comment := ""
|
||||
for _, output := range caseConf.Outputs {
|
||||
answer, err := os.ReadFile(output.AnswerPath)
|
||||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
|
||||
stdout, err := os.ReadFile(caseConf.StdoutPath)
|
||||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
// If no difference, assign score
|
||||
if compareChars(string(answer), result.Files[output.FileName], output.IgnoreWhitespace) {
|
||||
score += output.Score
|
||||
} else {
|
||||
// Convert answer to string and split by lines
|
||||
stdoutLines := strings.Split(string(answer), "\n")
|
||||
resultLines := strings.Split(result.Files[output.FileName], "\n")
|
||||
|
||||
comment = fmt.Sprintf(
|
||||
"executor status: run time: %d ns, memory: %d bytes\n",
|
||||
result.RunTime, result.Memory,
|
||||
)
|
||||
// Generate Myers diff
|
||||
diffOps := myersDiff(stdoutLines, resultLines)
|
||||
|
||||
// If no difference, assign score
|
||||
if compareChars(string(stdout), result.Files["stdout"], caseConf.IgnoreWhitespace) {
|
||||
score = caseConf.Score
|
||||
} else {
|
||||
// Convert stdout to string and split by lines
|
||||
stdoutLines := strings.Split(string(stdout), "\n")
|
||||
resultLines := strings.Split(result.Files["stdout"], "\n")
|
||||
|
||||
// Generate Myers diff
|
||||
diffOps := myersDiff(stdoutLines, resultLines)
|
||||
|
||||
// Generate diff block with surrounding context
|
||||
diffOutput := generateDiffWithContext(stdoutLines, resultLines, diffOps)
|
||||
comment += fmt.Sprintf(
|
||||
"difference found:\n```diff\n%s```",
|
||||
diffOutput,
|
||||
)
|
||||
// Generate diff block with surrounding context
|
||||
diffOutput := generateDiffWithContext(stdoutLines, resultLines, diffOps)
|
||||
comment += fmt.Sprintf(
|
||||
"difference found in %s:\n```diff\n%s```\n",
|
||||
output.FileName, diffOutput,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
res = append(res, stage.ParserResult{
|
||||
|
|
Loading…
Reference in New Issue
Block a user