github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/gojs/testdata/stdio/main.go (about) 1 package stdio 2 3 import ( 4 "errors" 5 "fmt" 6 "io" 7 "os" 8 "syscall" 9 ) 10 11 func Main() { 12 b, err := io.ReadAll(os.Stdin) 13 if err != nil { 14 panic(err) 15 } 16 17 if _, err = fmt.Fprintln(os.Stdin, " "); errors.Unwrap(err) != syscall.EBADF { 18 panic(fmt.Sprint(err.Error(), "!=", syscall.EBADF)) 19 } 20 printToFile("stdout", os.Stdout, len(b)) 21 printToFile("stderr", os.Stderr, len(b)) 22 } 23 24 func printToFile(name string, file *os.File, size int) { 25 message := fmt.Sprint(name, " ", size) 26 n, err := fmt.Fprintln(file, message) 27 if err != nil { 28 println(err.Error()) 29 panic(name) 30 } 31 if n != len(message)+1 /* \n */ { 32 println(n, "!=", len(message)) 33 panic(name) 34 } 35 }