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 {
|
type Conf struct {
|
||||||
Cases []struct {
|
Cases []struct {
|
||||||
Score int
|
Outputs []struct {
|
||||||
StdoutPath string
|
Score int
|
||||||
IgnoreWhitespace bool
|
FileName string
|
||||||
|
AnswerPath string
|
||||||
|
IgnoreWhitespace bool
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,35 +46,31 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
for i, caseConf := range conf.Cases {
|
for i, caseConf := range conf.Cases {
|
||||||
result := results[i]
|
result := results[i]
|
||||||
score := 0
|
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 no difference, assign score
|
||||||
if err != nil {
|
if compareChars(string(answer), result.Files[output.FileName], output.IgnoreWhitespace) {
|
||||||
return nil, true, err
|
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(
|
// Generate Myers diff
|
||||||
"executor status: run time: %d ns, memory: %d bytes\n",
|
diffOps := myersDiff(stdoutLines, resultLines)
|
||||||
result.RunTime, result.Memory,
|
|
||||||
)
|
|
||||||
|
|
||||||
// If no difference, assign score
|
// Generate diff block with surrounding context
|
||||||
if compareChars(string(stdout), result.Files["stdout"], caseConf.IgnoreWhitespace) {
|
diffOutput := generateDiffWithContext(stdoutLines, resultLines, diffOps)
|
||||||
score = caseConf.Score
|
comment += fmt.Sprintf(
|
||||||
} else {
|
"difference found in %s:\n```diff\n%s```\n",
|
||||||
// Convert stdout to string and split by lines
|
output.FileName, diffOutput,
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = append(res, stage.ParserResult{
|
res = append(res, stage.ParserResult{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user