Skip to content

Commit

Permalink
cmd/wit-bindgen-wrpc: add test for verbose generation
Browse files Browse the repository at this point in the history
This commit adds a test for verbose enabled/disabled generation,
ensuring that no output is provided if the verbose flags are not set.

Fixes #214

Signed-off-by: Victor Adossi <[email protected]>
  • Loading branch information
vados-cosmonic committed Oct 30, 2024
1 parent d0e1d41 commit d07f967
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/wit-bindgen-go/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"bytes"
"context"
"testing"
)

// TestSimpleGenVerbosity ensures that a basic generation case honors the verbose flag
func TestSimpleGenVerbosity(t *testing.T) {
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := Command
cmd.Writer = &stdout
cmd.ErrWriter = &stderr

args := []string{
"wit-bindgen-go",
"generate",
"--world",
"http-fetch-simple",
"--dry-run",
"../../testdata/codegen/simple-http.wit",
}

// 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")
}

stdout.Reset()
stderr.Reset()

// Run the app WITH verbose
cmd.Run(context.Background(), append(args, "-v"))
if stderr.Len() == 0 {
t.Errorf("no output was written to stderr when --verbose was used")
}
}

0 comments on commit d07f967

Please sign in to comment.