mirror of https://github.com/01-edu/public.git
Xavier Petit
5 years ago
committed by
xpetit
3 changed files with 15 additions and 22 deletions
@ -1,30 +1,19 @@ |
|||||||
package student_test |
package student_test |
||||||
|
|
||||||
import ( |
import ( |
||||||
"strings" |
"bytes" |
||||||
|
"os/exec" |
||||||
"testing" |
"testing" |
||||||
|
|
||||||
"github.com/01-edu/z01" |
|
||||||
) |
) |
||||||
|
|
||||||
func TestPrintProgramName(t *testing.T) { |
func TestPrintProgramName(t *testing.T) { |
||||||
exercise := strings.ToLower( |
b, err := exec.Command("go", "run", "./student/printprogramname").Output() |
||||||
strings.TrimPrefix(t.Name(), "Test")) |
if err != nil { |
||||||
out, err1 := z01.MainOut("./student/printprogramname") |
t.Fatal(err) |
||||||
if err1 != nil { |
|
||||||
t.Fatalf(err1.Error()) |
|
||||||
} |
|
||||||
|
|
||||||
correct, err2 := z01.MainOut("./solutions/printprogramname") |
|
||||||
|
|
||||||
if err2 != nil { |
|
||||||
t.Fatalf(err2.Error()) |
|
||||||
} |
} |
||||||
|
if string(bytes.TrimSpace(b)) != "printprogramname" { |
||||||
arrOut := strings.Split(out, "/") |
t.Fatal("Failed to print the program name") |
||||||
ArrCor := strings.Split(correct, "/") |
|
||||||
if ArrCor[len(ArrCor)-1] != arrOut[len(arrOut)-1] { |
|
||||||
t.Fatalf("./%s prints %q instead of %q\n", |
|
||||||
exercise, arrOut[len(arrOut)-1], ArrCor[len(ArrCor)-1]) |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
// TODO: add more test cases (different program names), to do so compile then rename and test the binary several times
|
||||||
|
Loading…
Reference in new issue