JOJ3/internal/parsers/diff/parser.go
张泊明518370910136 f5b6b3cc9a
All checks were successful
continuous-integration/drone/push Build is passing
feat: multiple cmds each stage
2024-03-05 01:38:16 -05:00

51 lines
1011 B
Go

package diff
import (
"fmt"
"os"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
)
type Config struct {
Cases []struct {
Score int
StdoutPath string
}
}
type Diff struct{}
func (e *Diff) Run(results []stage.ExecutorResult, configAny any) (
[]stage.ParserResult, error,
) {
config, err := stage.DecodeConfig[Config](configAny)
if err != nil {
return nil, err
}
if len(config.Cases) != len(results) {
return nil, fmt.Errorf("cases number not match")
}
var res []stage.ParserResult
for i, caseConfig := range config.Cases {
result := results[i]
score := 0
stdout, err := os.ReadFile(caseConfig.StdoutPath)
if err != nil {
return nil, err
}
// TODO: more compare strategies
if string(stdout) == result.Files["stdout"] {
score = caseConfig.Score
}
res = append(res, stage.ParserResult{
Score: score,
Comment: fmt.Sprintf(
"executor status: run time: %d ns, memory: %d bytes",
result.RunTime, result.Memory,
),
})
}
return res, nil
}