-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.go
74 lines (64 loc) · 1.8 KB
/
test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"github.com/nightrune/wrench/logging"
"os"
"path/filepath"
"strings"
)
const TEST_FILE_PATTERN = "*.test.nut"
var cmdTest = &Command{
UsageLine: "test",
Short: "Runs all tests it can find",
Long: "Recursively looks for files with the .test.nut type within the directory",
}
func init() {
cmdTest.Run = TestMe
}
func FindTestFiles() ([]string, error) {
var files []string
err := filepath.Walk("./", func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
location := path + "\\" + TEST_FILE_PATTERN
matches, err := filepath.Glob(location)
if err != nil {
return err
}
if len(matches) > 0 {
logging.Debug("Found these files: %s", matches)
files = append(files, matches...)
}
}
return nil
})
if err != nil {
return nil, err
}
return files, nil
}
func TestMe(cmd *Command, args []string) {
logging.Info("Attempting to find test scripts...")
test_files, err := FindTestFiles()
if err != nil {
os.Exit(1)
}
for _, input_file := range test_files {
split_file := strings.Split(input_file, ".")
// Remove test, and add .o
split_file = append(split_file[:len(split_file)-2], split_file[len(split_file)-1], "o")
output_file := strings.Join(split_file, ".")
logging.Info("Processing target: %s as output: %s", input_file, output_file)
err = PreProcessFile(output_file, input_file, cmd.settings.LibraryDirs)
if err != nil {
logging.Warn("Could not processes output file %s, got error: ", output_file, err.Error())
continue
}
logging.Info("Running target: %s", output_file)
err = ExecuteSqrl(output_file)
if err != nil {
logging.Warn("Could not run output_file %s, got error: ", output_file, err.Error())
continue
}
}
logging.Debug("All Files Found: %s", test_files)
logging.Info("Script finished")
}