feat(parser/diff): remove result status check
This commit is contained in:
parent
1ab6fa4583
commit
a001b26b66
|
@ -7,7 +7,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/criyle/go-judge/envexec"
|
|
||||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,8 +23,7 @@ type Conf struct {
|
||||||
PassComment string `default:"🥳Passed!\n"`
|
PassComment string `default:"🥳Passed!\n"`
|
||||||
FailComment string `default:"🧐Failed...\n"`
|
FailComment string `default:"🧐Failed...\n"`
|
||||||
Cases []struct {
|
Cases []struct {
|
||||||
IgnoreResultStatus bool
|
Outputs []struct {
|
||||||
Outputs []struct {
|
|
||||||
Score int
|
Score int
|
||||||
FileName string
|
FileName string
|
||||||
AnswerPath string
|
AnswerPath string
|
||||||
|
@ -54,51 +52,43 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
result := results[i]
|
result := results[i]
|
||||||
score := 0
|
score := 0
|
||||||
comment := ""
|
comment := ""
|
||||||
if !caseConf.IgnoreResultStatus &&
|
for _, output := range caseConf.Outputs {
|
||||||
result.Status != stage.Status(envexec.StatusAccepted) {
|
answer, err := os.ReadFile(output.AnswerPath)
|
||||||
forceQuit = true
|
if err != nil {
|
||||||
comment += fmt.Sprintf(
|
return nil, true, err
|
||||||
"Unexpected executor status: %s.", result.Status,
|
}
|
||||||
)
|
slog.Debug("compare", "filename", output.FileName,
|
||||||
} else {
|
"answer path", output.AnswerPath,
|
||||||
for _, output := range caseConf.Outputs {
|
"actual", result.Files[output.FileName],
|
||||||
answer, err := os.ReadFile(output.AnswerPath)
|
"answer", string(answer))
|
||||||
if err != nil {
|
// If no difference, assign score
|
||||||
return nil, true, err
|
if compareChars(string(answer), result.Files[output.FileName],
|
||||||
}
|
output.CompareSpace) {
|
||||||
slog.Debug("compare", "filename", output.FileName,
|
score += output.Score
|
||||||
"answer path", output.AnswerPath,
|
comment += conf.PassComment
|
||||||
"actual", result.Files[output.FileName],
|
} else {
|
||||||
"answer", string(answer))
|
comment += conf.FailComment
|
||||||
// If no difference, assign score
|
comment += fmt.Sprintf("Difference found in `%s`.\n",
|
||||||
if compareChars(string(answer), result.Files[output.FileName],
|
output.FileName)
|
||||||
output.CompareSpace) {
|
if !output.AlwaysHide {
|
||||||
score += output.Score
|
// Convert answer to string and split by lines
|
||||||
comment += conf.PassComment
|
stdoutLines := strings.Split(string(answer), "\n")
|
||||||
|
resultLines := strings.Split(
|
||||||
|
result.Files[output.FileName], "\n")
|
||||||
|
|
||||||
|
// Generate Myers diff
|
||||||
|
diffOps := myersDiff(stdoutLines, resultLines)
|
||||||
|
|
||||||
|
// Generate diff block with surrounding context
|
||||||
|
diffOutput := generateDiffWithContext(
|
||||||
|
stdoutLines, resultLines, diffOps)
|
||||||
|
diffOutput = strings.TrimSuffix(diffOutput, "\n \n")
|
||||||
|
comment += fmt.Sprintf(
|
||||||
|
"```diff\n%s\n```\n",
|
||||||
|
diffOutput,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
comment += conf.FailComment
|
comment += "(Content hidden.)\n"
|
||||||
comment += fmt.Sprintf("Difference found in `%s`.\n",
|
|
||||||
output.FileName)
|
|
||||||
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
|
|
||||||
diffOps := myersDiff(stdoutLines, resultLines)
|
|
||||||
|
|
||||||
// Generate diff block with surrounding context
|
|
||||||
diffOutput := generateDiffWithContext(
|
|
||||||
stdoutLines, resultLines, diffOps)
|
|
||||||
diffOutput = strings.TrimSuffix(diffOutput, "\n \n")
|
|
||||||
comment += fmt.Sprintf(
|
|
||||||
"```diff\n%s\n```\n",
|
|
||||||
diffOutput,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
comment += "(Content hidden.)\n"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user