github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/pipe/pipe_test.go (about) 1 package cmdpipe_test 2 3 import ( 4 "fmt" 5 "sync/atomic" 6 "testing" 7 8 _ "github.com/lmorg/murex/builtins" 9 "github.com/lmorg/murex/test" 10 ) 11 12 var uniqueID int32 13 14 func TestPipe(t *testing.T) { 15 id := atomic.AddInt32(&uniqueID, 1) 16 17 tests := []test.MurexTest{{ 18 Block: fmt.Sprintf(` 19 pipe: murextest%d 20 21 bg { 22 <murextest%d> -> match 2 23 } 24 out 1 -> <murextest%d> 25 out 2 -> <murextest%d> 26 out 3 -> <murextest%d> 27 28 sleep 1 29 !pipe: murextest%d 30 `, id, id, id, id, id, id), 31 ExitNum: 0, 32 Stdout: "2\n", 33 Stderr: ``, 34 }} 35 36 test.RunMurexTests(tests, t) 37 } 38 39 func TestPipe2(t *testing.T) { 40 id := atomic.AddInt32(&uniqueID, 1) 41 42 tests := []test.MurexTest{{ 43 Block: fmt.Sprintf(` 44 pipe: murextest%d 45 46 bg { 47 <murextest%d> 48 } 49 out 1 -> <murextest%d> 50 out 2 -> <murextest%d> 51 out 3 -> <murextest%d> 52 53 !pipe: murextest%d 54 `, id, id, id, id, id, id), 55 ExitNum: 0, 56 Stdout: "1\n2\n3\n", 57 Stderr: ``, 58 }} 59 60 test.RunMurexTests(tests, t) 61 } 62 63 func TestPipeOrderOfExecution(t *testing.T) { 64 // This test might seem counterintuitive with the `pipe` command at the end 65 // but `pipe` and `test` builtins in any given block are run before any 66 // other function to enable murexes interpreter to create murex named pipes 67 // before compiling the pipe stream into any other routine. The purpose of 68 // this test is to ensure that behavior still holds true rather than to 69 // demonstrate good practice of having `pipe` calls at the end of routines. 70 id := atomic.AddInt32(&uniqueID, 1) 71 72 tests := []test.MurexTest{{ 73 Block: fmt.Sprintf(` 74 bg { 75 <murextest%d> 76 } 77 out 1 -> <murextest%d> 78 out 2 -> <murextest%d> 79 out 3 -> <murextest%d> 80 81 !pipe: murextest%d 82 pipe: murextest%d 83 `, id, id, id, id, id, id), 84 ExitNum: 0, 85 Stdout: "1\n2\n3\n", 86 Stderr: ``, 87 }} 88 89 test.RunMurexTests(tests, t) 90 }