Skip to content

Commit

Permalink
test: Support to more common -update flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Dec 6, 2023
1 parent 146fac3 commit 7906f33
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

### Tests

- WRITE_ACTUAL does not preserve comment order for readlines
- update tests does not preserve comment order for readlines
- empty file test
- CLI tests, raw write, colors?
- Interactive tests
Expand Down
10 changes: 5 additions & 5 deletions doc/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Flags can be struct with bit-fields.
- If possible use a pair of `testdata/file` and `testdata/file.fqtest` where `file.fqtest` is `$ fq dv file` or `$ fq 'dv,torepr' file` if there is `torepr` support.
- If `dv` produces a lof of output maybe use `dv({array_truncate: 50})` etc
- Run `go test ./format -run TestFormats/<name>` to test expected output.
- Run `WRITE_ACTUAL=1 go test ./format -run TestFormats/<name>` to write current output as expected output.
- Run `go test ./format -run TestFormats/<name> -update` to update current output as expected output.
- If you have format specific documentation:
- Put it in `format/*/<name>.md` and use `//go:embed <name>.md`/`interp.RegisterFS(..)` to embed/register it.
- Use simple markdown, just sections (depth starts at 3, `### Section`), paragraphs, lists and links.
Expand Down Expand Up @@ -236,10 +236,10 @@ make test
go test ./...
# run all tests for one format
go test -run TestFormats/mp4 ./format/
# write all actual outputs
WRITE_ACTUAL=1 go test ./...
# write actual output for specific tests
WRITE_ACTUAL=1 go run -run ...
# update all actual outputs in tests
go test ./... -update
# update actual output for specific tests
go run ./format -run TestFormats/elf -update
# color diff
DIFF_COLOR=1 go test ...
```
Expand Down
5 changes: 4 additions & 1 deletion format/fqtest_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package format_test

import (
"flag"
"testing"

_ "github.com/wader/fq/format/all"
"github.com/wader/fq/pkg/fqtest"
"github.com/wader/fq/pkg/interp"
)

var update = flag.Bool("update", false, "Update tests")

func TestFormats(t *testing.T) {
fqtest.TestPath(t, interp.DefaultRegistry)
fqtest.TestPath(t, interp.DefaultRegistry, *update)
}
2 changes: 1 addition & 1 deletion format/tzif/testdata/generate_fqtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tear_down() {
echo "$ fq -d tzif dv $f" > "$of"
done

WRITE_ACTUAL=1 go test -run TestFQTests/tzif "$d/../.."
go test -run TestFQTests/tzif "$d/../.." -update
if grep "error" ./*.fqtest; then
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion format/wasm/testdata/core/generate_fqtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tear_down() {
echo "$ fq -d wasm dv $f" > "$of"
done

WRITE_ACTUAL=1 go test -run TestFQTests/wasm "$d/../../.."
go test -run TestFQTests/wasm "$d/../../.." -update
if grep "error" ./*.fqtest; then
exit 1
fi
Expand Down
4 changes: 2 additions & 2 deletions pkg/fqtest/fqtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/wader/fq/pkg/interp"
)

func TestPath(t *testing.T, registry *interp.Registry) {
func TestPath(t *testing.T, registry *interp.Registry, update bool) {
difftest.TestWithOptions(t, difftest.Options{
Path: ".",
Pattern: "*.fqtest",
ColorDiff: os.Getenv("DIFF_COLOR") != "",
WriteOutput: os.Getenv("WRITE_ACTUAL") != "",
WriteOutput: os.Getenv("WRITE_ACTUAL") != "" || update,
Fn: func(t *testing.T, path, input string) (string, string, error) {
t.Parallel()

Expand Down
5 changes: 4 additions & 1 deletion pkg/interp/fqtest_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package interp_test

import (
"flag"
"testing"

_ "github.com/wader/fq/format/all"
"github.com/wader/fq/pkg/fqtest"
"github.com/wader/fq/pkg/interp"
)

var update = flag.Bool("update", false, "Update tests")

func TestInterp(t *testing.T) {
fqtest.TestPath(t, interp.DefaultRegistry)
fqtest.TestPath(t, interp.DefaultRegistry, *update)
}

0 comments on commit 7906f33

Please sign in to comment.