From dec0a7b659187f1dfc14d1876ccd989d06235b53 Mon Sep 17 00:00:00 2001 From: xpetit <32063953+xpetit@users.noreply.github.com> Date: Fri, 7 Aug 2020 11:17:14 +0200 Subject: [PATCH] Fix raid3 --- go/tests/prog/raid3_test/main.go | 40 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/go/tests/prog/raid3_test/main.go b/go/tests/prog/raid3_test/main.go index 52941139b..c9fb5f5ae 100644 --- a/go/tests/prog/raid3_test/main.go +++ b/go/tests/prog/raid3_test/main.go @@ -4,51 +4,43 @@ import ( "os/exec" "strconv" - "github.com/01-edu/public/go/lib" + "lib" ) func main() { execFatal := func(name string, arg ...string) string { b, err := exec.Command(name, arg...).CombinedOutput() - s := string(b) - if err != nil { - lib.Fatal(s) + if _, ok := err.(*exec.ExitError); ok { + lib.Fatalf("%s\n", b) + } else { + lib.Fatalf("%s\n", err) } - return s + return string(b) } // executes the test and compares student with solutions - executeTest := func(args string, x, y int) { + executeTest := func(name string, x, y int) { var output, correct string if x == 0 && y == 0 { - output = execFatal("sh", "-c", args+" | ./raid3_student") - correct = execFatal("sh", "-c", args+" | ./raid3") + output = execFatal("sh", "-c", name+" | ./raid3") + correct = execFatal("sh", "-c", name+" | raid3_prog") } else { - output = execFatal("sh", "-c", "./"+args+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3_student") - correct = execFatal("sh", "-c", "./"+args+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3") + output = execFatal("sh", "-c", "./"+name+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3") + correct = execFatal("sh", "-c", "./"+name+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | raid3_prog") } if output != correct { lib.Fatalf("./%s %d %d | ./raid3 prints %q instead of %q\n", - args, x, y, output, correct) + name, x, y, output, correct) } } - // builds all the files for testing, student, solution and relevant files - execFatal("go", "build", "-o", "raid3", "solutions/raid3/main.go") - execFatal("go", "build", "-o", "raid3_student", "student/raid3/main.go") - execFatal("go", "build", "solutions/raid3/raid1aprog/raid1a.go") - execFatal("go", "build", "solutions/raid3/raid1bprog/raid1b.go") - execFatal("go", "build", "solutions/raid3/raid1cprog/raid1c.go") - execFatal("go", "build", "solutions/raid3/raid1dprog/raid1d.go") - execFatal("go", "build", "solutions/raid3/raid1eprog/raid1e.go") - // testing all raids1 - table := []string{"raid1a", "raid1b", "raid1c", "raid1d", "raid1e"} - for _, s := range table { + names := []string{"raid1a", "raid1b", "raid1c", "raid1d", "raid1e"} + for _, name := range names { x := lib.RandIntBetween(1, 50) y := lib.RandIntBetween(1, 50) - executeTest(s, x, y) + executeTest(name, x, y) } // testing special case AA, AC, A, A @@ -60,5 +52,3 @@ func main() { executeTest("raid1e", 1, 1) executeTest("echo", 0, 0) } - -// TODO: fix paths