mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.7 KiB
77 lines
1.7 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"strings"
|
||
|
|
||
5 years ago
|
"../lib"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func main() {
|
||
|
pathFileName1 := "./student/cat/quest8.txt"
|
||
|
pathFileName2 := "./student/cat/quest8T.txt"
|
||
5 years ago
|
|
||
5 years ago
|
if _, err := os.Stat(pathFileName1); err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
5 years ago
|
if _, err := os.Stat(pathFileName2); err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
5 years ago
|
table := []string{pathFileName1, pathFileName1 + " " + pathFileName2, "asd"}
|
||
5 years ago
|
|
||
|
for _, s := range table {
|
||
5 years ago
|
lib.ChallengeMain("cat", strings.Fields(s)...)
|
||
5 years ago
|
}
|
||
5 years ago
|
if _, err := exec.Command("go", "build", "-o", "cat_student", "./student/cat/main.go").Output(); err != nil {
|
||
5 years ago
|
lib.Fatal(string(err.(*exec.ExitError).Stderr))
|
||
5 years ago
|
}
|
||
|
if _, err := exec.Command("go", "build", "-o", "cat_solution", "./solutions/cat/main.go").Output(); err != nil {
|
||
5 years ago
|
lib.Fatal(string(err.(*exec.ExitError).Stderr))
|
||
5 years ago
|
}
|
||
|
pwd, err := os.Getwd()
|
||
|
if err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
|
|
||
|
for i := 0; i < 2; i++ {
|
||
5 years ago
|
randStdin := lib.RandAlnum()
|
||
5 years ago
|
cmd := exec.Command("sh", "-c", pwd+"/cat_solution")
|
||
|
solutionResult := execStdin(cmd, randStdin)
|
||
|
cmdS := exec.Command(pwd + "/cat_student")
|
||
|
studentResult := execStdin(cmdS, randStdin)
|
||
|
|
||
|
if solutionResult != studentResult {
|
||
5 years ago
|
lib.Fatalf("./cat prints %s instead of %s\n", studentResult, solutionResult)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func execStdin(cmd *exec.Cmd, randomStdin string) string {
|
||
|
stdin, err := cmd.StdinPipe()
|
||
|
if err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
|
stdout, err := cmd.StdoutPipe()
|
||
|
if err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
|
if err := cmd.Start(); err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
|
_, err = stdin.Write([]byte(randomStdin))
|
||
|
if err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
|
stdin.Close()
|
||
|
|
||
|
out, _ := ioutil.ReadAll(stdout)
|
||
|
if err := cmd.Wait(); err != nil {
|
||
5 years ago
|
lib.Fatalln(err)
|
||
5 years ago
|
}
|
||
|
return string(out)
|
||
|
}
|
||
5 years ago
|
|
||
|
// TODO: handle stdin in ChallengeMain
|