MCPcopy
hub / github.com/lmorg/murex / RunMurexTests

Function RunMurexTests

test/murex.go:29–100  ·  view source on GitHub ↗

RunMurexTests runs through all the test cases for MurexTest where STDOUT/ERR are literal strings

(tests []MurexTest, t *testing.T)

Source from the content-addressed store, hash-verified

27
28// RunMurexTests runs through all the test cases for MurexTest where STDOUT/ERR are literal strings
29func RunMurexTests(tests []MurexTest, t *testing.T) {
30 t.Helper()
31 count.Tests(t, len(tests))
32
33 defaults.Config(config.InitConf, false)
34 lang.InitEnv()
35
36 for i := range tests {
37 hasError := false
38
39 fork := lang.ShellProcess.Fork(lang.F_FUNCTION | lang.F_NEW_MODULE | lang.F_NO_STDIN | lang.F_CREATE_STDOUT | lang.F_CREATE_STDERR)
40 go func(testNum int) {
41 time.Sleep(_TIMEOUT_SECONDS * time.Second)
42 if !fork.Process.HasCancelled() {
43 panic(fmt.Sprintf("timeout in %s() test %d", t.Name(), testNum))
44 }
45 }(i)
46
47 fork.Name.Set("RunMurexTests()")
48 fork.FileRef = &ref.File{Source: &ref.Source{Module: fmt.Sprintf("murex/%s-%d", t.Name(), i)}}
49 exitNum, err := fork.Execute([]rune(tests[i].Block))
50 if err != nil {
51 t.Errorf("Cannot execute script on test %d", i)
52 t.Log(" ", err)
53 continue
54 }
55
56 bErr, err := fork.Stderr.ReadAll()
57 if err != nil {
58 t.Errorf("Cannot ReadAll() from Stderr on test %d", i)
59 t.Log(" ", err)
60 continue
61 }
62
63 if string(bErr) != tests[i].Stderr {
64 hasError = true
65 }
66
67 bOut, err := fork.Stdout.ReadAll()
68 if err != nil {
69 t.Errorf("Cannot ReadAll() from Stdout on test %d", i)
70 t.Log(" ", err)
71 continue
72 }
73
74 if string(bOut) != tests[i].Stdout {
75 hasError = true
76 }
77
78 if exitNum != tests[i].ExitNum {
79 hasError = true
80 }
81
82 if hasError {
83 t.Errorf("Code block doesn't return expected values in test %d", i)
84 t.Log(" Code block: ", tests[i].Block)
85
86 t.Log(" Expected Stdout: ", strings.Replace(tests[i].Stdout, "\n", `\n`, -1))

Callers 15

TestBugFixFunction · 0.92
TestExecPipeRedirectFunction · 0.92
TestVarGlobalFunction · 0.92
TestVarEnvFunction · 0.92
TestOperatorLogicAndTryFunction · 0.92
TestOperatorLogicOrTryFunction · 0.92
TestOperatorsTryFunction · 0.92
TestRedirectionFunction · 0.92

Calls 8

TestsFunction · 0.92
ConfigFunction · 0.92
InitEnvFunction · 0.92
ForkMethod · 0.80
HasCancelledMethod · 0.80
ExecuteMethod · 0.80
SetMethod · 0.65
ReadAllMethod · 0.65

Tested by 15

TestBugFixFunction · 0.74
TestExecPipeRedirectFunction · 0.74
TestVarGlobalFunction · 0.74
TestVarEnvFunction · 0.74
TestOperatorLogicAndTryFunction · 0.74
TestOperatorLogicOrTryFunction · 0.74
TestOperatorsTryFunction · 0.74
TestRedirectionFunction · 0.74