File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,12 @@ package main
33import (
44 "bytes"
55 "os"
6+ "regexp"
67 "testing"
78)
89
10+ var ansiRegex = regexp .MustCompile (`\x1b\[[0-9;]*m` )
11+
912func captureOutput (f func ()) string {
1013 var buf bytes.Buffer
1114 stdout := os .Stdout
@@ -21,6 +24,10 @@ func captureOutput(f func()) string {
2124 return buf .String ()
2225}
2326
27+ func stripANSI (input string ) string {
28+ return ansiRegex .ReplaceAllString (input , "" )
29+ }
30+
2431func TestRunCLI (t * testing.T ) {
2532 tests := []struct {
2633 name string
@@ -118,6 +125,8 @@ func TestRunCLI(t *testing.T) {
118125 }
119126 })
120127
128+ output = stripANSI (output )
129+
121130 if ! bytes .Contains ([]byte (output ), []byte (tt .expectedOutput )) {
122131 t .Errorf ("Expected output to contain %q, got %q" , tt .expectedOutput , output )
123132 }
You can’t perform that action at this time.
0 commit comments