-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfatal_test.go
More file actions
55 lines (53 loc) · 2.01 KB
/
Copy pathfatal_test.go
File metadata and controls
55 lines (53 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ansi
import (
"bytes"
"fmt"
"os/exec"
"testing"
)
func TestAnsi_Fatal(t *testing.T) {
t.Run("test ansi.Fatal() with exit code 0", func(t *testing.T) {
cmd := "go"
args := []string{"run", "example/fatal.go"}
actual, err := exec.Command(cmd, args...).Output()
if err != nil {
t.Fatalf("Failed to run test program:\nerr: %v\nout: %v", err, actual)
}
expectedAnsiResetCodes := []byte{27, 91, 48, 109, 99, 111, 100, 101, 58, 32, 48, 27, 91, 48, 109}
if !bytes.Equal(actual, expectedAnsiResetCodes) {
t.Fatalf("exit code should return no output.\n"+
" got: '%s' %v\n"+
"expected: '%v'\n", string(actual), actual, expectedAnsiResetCodes)
}
})
t.Run("test ansi.Fatal() with exit code 1", func(t *testing.T) {
code := 1
cmd := "go"
args := []string{"run", "example/fatal.go", "-code", fmt.Sprintf("%d", code)}
actual, err := exec.Command(cmd, args...).Output()
if err != nil && err.Error() != fmt.Sprintf("exit status %d", code) {
t.Fatalf("Failed to run test program:\nerr: %v\nout: %v", err, actual)
}
expectedAnsiResetCodes := []byte{27, 91, 48, 109, 99, 111, 100, 101, 58, 32, 49, 27, 91, 48, 109}
if !bytes.Equal(actual, expectedAnsiResetCodes) {
t.Fatalf("exit code should return no output.\n"+
" got: '%s' %v\n"+
"expected: '%v'\n", string(actual), actual, expectedAnsiResetCodes)
}
})
t.Run("test ansi.Fatal() with exit code 2", func(t *testing.T) {
code := 2
cmd := "go"
args := []string{"run", "example/fatal.go", "-code", fmt.Sprintf("%d", code)}
actual, err := exec.Command(cmd, args...).Output()
if err != nil && err.Error() != fmt.Sprintf("exit status %d", 1) {
t.Fatalf("Failed to run test program:\nerr: %v\nout: %v", err, actual)
}
expectedAnsiResetCodes := []byte{27, 91, 48, 109, 99, 111, 100, 101, 58, 32, 50, 27, 91, 48, 109}
if !bytes.Equal(actual, expectedAnsiResetCodes) {
t.Fatalf("exit code should return no output.\n"+
" got: '%s' %v\n"+
"expected: '%v'\n", string(actual), actual, expectedAnsiResetCodes)
}
})
}