-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain_test.go
57 lines (48 loc) · 1.25 KB
/
main_test.go
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
// TODO: Remove the following go:build line when TinyGo supports Go 1.24.
//go:build !(tinygo && go1.24)
package main
import (
"bytes"
"context"
"strings"
"testing"
)
// TestSimpleGenVerbosity ensures that a basic generation case honors the verbose flag
func TestSimpleGenVerbosity(t *testing.T) {
inWIT := `package tests:test;`
stdin := strings.NewReader(inWIT)
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := Command
cmd.Reader = stdin
cmd.Writer = &stdout
cmd.ErrWriter = &stderr
args := []string{
"wit-bindgen-go",
"generate",
"--world",
"http-fetch-simple",
"--dry-run",
"-",
}
// Run the app without verbose
cmd.Run(context.Background(), args)
if stderr.Len() != 0 {
t.Errorf("output was written to stderr despite lack of --verbose")
}
stdin.Reset(inWIT)
stdout.Reset()
stderr.Reset()
cmd.Run(context.Background(), append(args, "-v"))
if stderr.Len() == 0 {
t.Errorf("no output was written to stderr when -v was used")
}
cmd.Run(context.Background(), append(args, "-vv"))
if stderr.Len() == 0 {
t.Errorf("no output was written to stderr when -vv was used")
}
cmd.Run(context.Background(), append(args, "--verbose"))
if stderr.Len() == 0 {
t.Errorf("no output was written to stderr when --verbose was used")
}
}