-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
60 lines (46 loc) · 1.01 KB
/
main_test.go
File metadata and controls
60 lines (46 loc) · 1.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
56
57
58
59
60
package main
import (
"os"
"strings"
"testing"
)
func TestMain(m *testing.M) {
// Run tests
os.Exit(m.Run())
}
func TestShowVersion(t *testing.T) {
// Redirect stdout to capture output
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
showVersion()
w.Close()
os.Stdout = old
// Read the output
buf := make([]byte, 1024)
n, _ := r.Read(buf)
// Check if the version is printed
if !contains(string(buf[:n]), VERSION) {
t.Errorf("Expected version %s to be printed", VERSION)
}
}
func TestShowCompassArt(t *testing.T) {
// Redirect stdout to capture output
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
showCompassArt()
w.Close()
os.Stdout = old
// Read the output
buf := make([]byte, 1024)
n, _ := r.Read(buf)
// Check if the compass art is printed
if !contains(string(buf[:n]), "CodeCompass") {
t.Errorf("Expected compass art to be printed")
}
}
// Helper function to check if a string contains a substring
func contains(s, substr string) bool {
return strings.Contains(s, substr)
}