MCPcopy Index your code
hub / github.com/cortesi/modd / testCmd

Function testCmd

shell/shell_test.go:27–90  ·  view source on GitHub ↗
(t *testing.T, shell string, ct cmdTest)

Source from the content-addressed store, hash-verified

25}
26
27func testCmd(t *testing.T, shell string, ct cmdTest) {
28 if ct.shells != nil {
29 issh := func() bool {
30 for _, v := range ct.shells {
31 if v == shell {
32 return true
33 }
34 }
35 return false
36 }()
37 if !issh {
38 t.Skip("skipping")
39 return
40 }
41 }
42
43 lt := termlog.NewLogTest()
44 exec, err := NewExecutor(shell, ct.cmd, "")
45 if err != nil {
46 t.Error(err)
47 return
48 }
49 type result struct {
50 err error
51 pstate *ExecState
52 }
53
54 ch := make(chan result)
55 go func() {
56 err, pstate := exec.Run(lt.Log.Stream(""), ct.bufferr)
57 ch <- result{err: err, pstate: pstate}
58 }()
59
60 // Wait for the first output to make sure process is running
61 for {
62 time.Sleep(100 * time.Millisecond)
63 if lt.String() != "" {
64 break
65 }
66 }
67
68 if ct.kill {
69 err := exec.Stop()
70 if err != nil {
71 t.Errorf("Error stopping: %s", err)
72 return
73 }
74 time.Sleep(1 * time.Second)
75 }
76
77 res := <-ch
78 if (res.err != nil) != ct.err {
79 t.Errorf("Unexpected invocation error: %s", err)
80 }
81 if (res.pstate.Error != nil) != ct.procerr {
82 t.Errorf("Unexpected process error: %s, %s", res.pstate.Error, res.pstate.ErrOutput)
83 }
84 if ct.buffHas != "" && !strings.Contains(res.pstate.ErrOutput, ct.buffHas) {

Callers 1

TestShellsFunction · 0.85

Calls 5

RunMethod · 0.95
StopMethod · 0.95
NewExecutorFunction · 0.85
ErrorMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected