Skip to content

Commit bdaacf2

Browse files
committed
cmd/wit-bindgen-go: silence test
1 parent e105312 commit bdaacf2

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

cmd/wit-bindgen-go/cmd/generate/generate.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"path/filepath"
88
"strings"
99

10+
"github.com/urfave/cli/v3"
1011
"go.bytecodealliance.org/internal/codec"
1112
"go.bytecodealliance.org/internal/go/gen"
1213
"go.bytecodealliance.org/internal/witcli"
1314
"go.bytecodealliance.org/wit/bindgen"
1415
"go.bytecodealliance.org/wit/logging"
15-
"github.com/urfave/cli/v3"
1616
)
1717

1818
// Command is the CLI command for wit.
@@ -80,7 +80,7 @@ type config struct {
8080
}
8181

8282
func action(ctx context.Context, cmd *cli.Command) error {
83-
cfg, err := parseFlags(cmd)
83+
cfg, err := parseFlags(ctx, cmd)
8484
if err != nil {
8585
return err
8686
}
@@ -102,10 +102,10 @@ func action(ctx context.Context, cmd *cli.Command) error {
102102
return err
103103
}
104104

105-
return writeGoPackages(packages, cfg)
105+
return writeGoPackages(ctx, cmd, cfg, packages)
106106
}
107107

108-
func parseFlags(cmd *cli.Command) (*config, error) {
108+
func parseFlags(_ context.Context, cmd *cli.Command) (*config, error) {
109109
logger := witcli.Logger(cmd.Bool("verbose"), cmd.Bool("debug"))
110110
dryRun := cmd.Bool("dry-run")
111111
out := cmd.String("out")
@@ -145,7 +145,7 @@ func parseFlags(cmd *cli.Command) (*config, error) {
145145
}, nil
146146
}
147147

148-
func writeGoPackages(packages []*gen.Package, cfg *config) error {
148+
func writeGoPackages(_ context.Context, cmd *cli.Command, cfg *config, packages []*gen.Package) error {
149149
cfg.logger.Infof("Generated %d Go package(s)\n", len(packages))
150150
for _, pkg := range packages {
151151
if !pkg.HasContent() {
@@ -179,8 +179,8 @@ func writeGoPackages(packages []*gen.Package, cfg *config) error {
179179
}
180180

181181
if cfg.dryRun {
182-
fmt.Println(string(content))
183-
fmt.Println()
182+
fmt.Fprintln(cmd.Writer, string(content))
183+
fmt.Fprintln(cmd.Writer)
184184
continue
185185
}
186186

cmd/wit-bindgen-go/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var version = &cli.Command{
6464
Name: "version",
6565
Usage: "print the version",
6666
Action: func(ctx context.Context, cmd *cli.Command) error {
67-
fmt.Printf("%s version %s\n", cmd.Root().Name, witcli.Version())
67+
fmt.Fprintf(cmd.Writer, "%s version %s\n", cmd.Root().Name, witcli.Version())
6868
return nil
6969
},
7070
}

cmd/wit-bindgen-go/main_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ package main
33
import (
44
"bytes"
55
"context"
6+
"strings"
67
"testing"
78
)
89

910
// TestSimpleGenVerbosity ensures that a basic generation case honors the verbose flag
1011
func TestSimpleGenVerbosity(t *testing.T) {
12+
inWIT := `package tests:test;`
13+
stdin := strings.NewReader(inWIT)
1114
var stdout bytes.Buffer
1215
var stderr bytes.Buffer
1316
cmd := Command
17+
cmd.Reader = stdin
1418
cmd.Writer = &stdout
1519
cmd.ErrWriter = &stderr
1620

@@ -20,7 +24,7 @@ func TestSimpleGenVerbosity(t *testing.T) {
2024
"--world",
2125
"http-fetch-simple",
2226
"--dry-run",
23-
"../../testdata/codegen/simple-http.wit",
27+
"-",
2428
}
2529

2630
// Run the app without verbose
@@ -29,6 +33,7 @@ func TestSimpleGenVerbosity(t *testing.T) {
2933
t.Errorf("output was written to stderr despite lack of --verbose")
3034
}
3135

36+
stdin.Reset(inWIT)
3237
stdout.Reset()
3338
stderr.Reset()
3439

0 commit comments

Comments
 (0)