github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/test_compare_stdio.go (about) 1 package lang 2 3 /* 4 This test library relates to the testing framework within the murex 5 language itself rather than Go's test framework within the murex project. 6 7 The naming convention here is basically the inverse of Go's test naming 8 convention. ie Go source files will be named "test_unit.go" (because 9 calling it unit_test.go would mean it's a Go test rather than murex test) 10 and the code is named UnitTestPlans (etc) rather than TestUnitPlans (etc) 11 because the latter might suggest they would be used by `go test`. This 12 naming convention is a little counterintuitive but it at least avoids 13 naming conflicts with `go test`. 14 */ 15 16 import ( 17 "github.com/lmorg/murex/lang/stdio" 18 ) 19 20 func testBlock(test *TestProperties, p *Process, block []rune, stdin []byte, dt string, property string, failed *bool) { 21 fork := p.Fork(F_FUNCTION | F_CREATE_STDIN | F_CREATE_STDERR | F_CREATE_STDOUT) 22 fork.IsMethod = true 23 fork.Name.Set("(pipe test " + property + ")") 24 fork.Stdin.SetDataType(dt) 25 _, err := fork.Stdin.Write(stdin) 26 if err != nil { 27 p.Tests.AddResult(test, p, TestError, tMsgWriteErr(property, err)) 28 *failed = true 29 return 30 } 31 32 exitNum, err := fork.Execute(block) 33 if err != nil { 34 p.Tests.AddResult(test, p, TestError, tMsgCompileErr(property, err)) 35 return 36 } 37 38 if exitNum == 0 { 39 p.Tests.AddResult(test, p, TestInfo, tMsgExitNumZero(property)) 40 } else { 41 p.Tests.AddResult(test, p, TestFailed, tMsgExitNumNotZero(property, exitNum)) 42 *failed = true 43 } 44 45 testReadAllOut(test, p, fork.Stdout, property, failed) 46 testReadAllErr(test, p, fork.Stderr, property, failed) 47 } 48 49 func testReadAllOut(test *TestProperties, p *Process, std stdio.Io, property string, failed *bool) { 50 b, err := std.ReadAll() 51 if err != nil { 52 p.Tests.AddResult(test, p, TestError, tMsgReadErr("stdout", property, err)) 53 *failed = true 54 } 55 56 if len(b) != 0 { 57 p.Tests.AddResult(test, p, TestInfo, tMsgStdout(property, b)) 58 *failed = true 59 } 60 } 61 62 func testReadAllErr(test *TestProperties, p *Process, std stdio.Io, property string, failed *bool) { 63 b, err := std.ReadAll() 64 if err != nil { 65 p.Tests.AddResult(test, p, TestError, tMsgReadErr("stderr", property, err)) 66 *failed = true 67 } 68 69 if len(b) != 0 { 70 p.Tests.AddResult(test, p, TestFailed, tMsgStderr(property, b)) 71 *failed = true 72 } 73 }