-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
46 lines (40 loc) · 1.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/exercism/go-test-runner/testrunner"
)
func main() {
if len(os.Args) != 3 {
log.Fatal("usage: go-test-runner input_dir output_dir")
}
input_dir := os.Args[1]
output_dir := os.Args[2]
msg, ok := checkArgs(input_dir, output_dir)
if !ok {
log.Fatal(msg)
}
report := testrunner.Execute(input_dir)
results := filepath.Join(output_dir, "results.json")
err := os.WriteFile(results, report, 0644)
if err != nil {
log.Fatalf("Failed to write results.json: %s", err)
}
}
func checkArgs(input_dir string, output_dir string) (string, bool) {
if _, err := os.Stat(input_dir); os.IsNotExist(err) {
return fmt.Sprintf("input_dir does not exist: %s", input_dir), false
}
if _, err := os.Stat(output_dir); os.IsNotExist(err) {
log.Printf("output_dir does not exist, creating: %s", output_dir)
if err := os.Mkdir(output_dir, os.ModeDir|0755); err != nil {
msg := fmt.Sprintf("output_dir %s does not exist, mkdir failed: %s",
output_dir, err,
)
return msg, false
}
}
return "", true
}