fixes
Some checks failed
judge / Build judge (push) Successful in 8s
judge / Linux / gcc / Debug (push) Successful in 7s
judge / Linux / clang / Release (push) Successful in 9s
judge / Linux / gcc / Release (push) Successful in 10s
judge / Linux / clang / Sanitized (push) Successful in 8s
judge / Linux / gcc / Sanitized (push) Successful in 9s
judge / Linux / gcc / Debug (valgrind) (push) Successful in 15s
judge / Windows / clang / Debug (push) Successful in 37s
judge / Windows / clang / Release (push) Successful in 40s
judge / Windows / msvc / Debug (push) Successful in 45s
judge / Windows / msvc / Release (push) Successful in 43s
judge / SUMMARY (push) Failing after 2s
Some checks failed
judge / Build judge (push) Successful in 8s
judge / Linux / gcc / Debug (push) Successful in 7s
judge / Linux / clang / Release (push) Successful in 9s
judge / Linux / gcc / Release (push) Successful in 10s
judge / Linux / clang / Sanitized (push) Successful in 8s
judge / Linux / gcc / Sanitized (push) Successful in 9s
judge / Linux / gcc / Debug (valgrind) (push) Successful in 15s
judge / Windows / clang / Debug (push) Successful in 37s
judge / Windows / clang / Release (push) Successful in 40s
judge / Windows / msvc / Debug (push) Successful in 45s
judge / Windows / msvc / Release (push) Successful in 43s
judge / SUMMARY (push) Failing after 2s
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Mond1c/judge/dsl"
|
||||
"github.com/Mond1c/judge/reporter"
|
||||
@@ -28,23 +28,25 @@ Example:
|
||||
`
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
fs := flag.NewFlagSet("judge", flag.ContinueOnError)
|
||||
fs.SetOutput(os.Stderr)
|
||||
fs.Usage = func() { fmt.Fprint(os.Stderr, usage) }
|
||||
|
||||
if len(args) == 0 || contains(args, "--help") || contains(args, "-h") {
|
||||
fmt.Print(usage)
|
||||
os.Exit(0)
|
||||
jsonOutput := fs.Bool("json", false, "output as JSON")
|
||||
wrapper := fs.String("wrapper", "", "exec wrapper command")
|
||||
binary := fs.String("binary", "", "binary name override")
|
||||
|
||||
if err := fs.Parse(os.Args[1:]); err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
if fs.NArg() < 2 {
|
||||
fmt.Fprintf(os.Stderr, "error: need <tests.jdg> and <solution-dir>\n\n%s", usage)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
testFile := args[0]
|
||||
solutionDir := args[1]
|
||||
jsonOutput := contains(args, "--json")
|
||||
wrapper := flagValue(args, "--wrapper")
|
||||
binary := flagValue(args, "--binary")
|
||||
testFile := fs.Arg(0)
|
||||
solutionDir := fs.Arg(1)
|
||||
|
||||
src, err := os.ReadFile(testFile)
|
||||
if err != nil {
|
||||
@@ -65,12 +67,12 @@ func main() {
|
||||
|
||||
r := runner.New(f, runner.Config{
|
||||
WorkDir: solutionDir,
|
||||
BinaryName: binary,
|
||||
Wrapper: wrapper,
|
||||
BinaryName: *binary,
|
||||
Wrapper: *wrapper,
|
||||
})
|
||||
result := r.Run()
|
||||
|
||||
if jsonOutput {
|
||||
if *jsonOutput {
|
||||
if err := reporter.JSON(os.Stdout, result); err != nil {
|
||||
fatalf("json output error: %v", err)
|
||||
}
|
||||
@@ -87,26 +89,3 @@ func fatalf(msg string, args ...any) {
|
||||
fmt.Fprintf(os.Stderr, "error: "+msg+"\n", args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// flagValue returns the value of --name <value> or --name=value, else "".
|
||||
func flagValue(args []string, name string) string {
|
||||
prefix := name + "="
|
||||
for i, a := range args {
|
||||
if a == name && i+1 < len(args) {
|
||||
return args[i+1]
|
||||
}
|
||||
if strings.HasPrefix(a, prefix) {
|
||||
return a[len(prefix):]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func contains(slice []string, s string) bool {
|
||||
for _, v := range slice {
|
||||
if v == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user