Skip to content

Commit

Permalink
syntax: swap frankban/quicktest for go-quicktest/qt
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Feb 25, 2024
1 parent 2574323 commit 0763f7d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/creack/pty v1.1.21
github.com/frankban/quicktest v1.14.6
github.com/go-quicktest/qt v1.101.0
github.com/google/go-cmp v0.6.0
github.com/google/renameio/v2 v2.0.0
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/renameio/v2 v2.0.0 h1:UifI23ZTGY8Tt29JbYFiuyIU3eX+RNFtUwefq9qAhxg=
Expand Down
8 changes: 4 additions & 4 deletions syntax/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

qt "github.com/frankban/quicktest"
"github.com/go-quicktest/qt"
)

func FuzzQuote(f *testing.F) {
Expand Down Expand Up @@ -61,10 +61,10 @@ func FuzzQuote(f *testing.F) {
if err != nil {
t.Fatalf("parse error on %q quoted as %s: %v", s, quoted, err)
}
qt.Assert(t, len(f.Stmts), qt.Equals, 1, qt.Commentf("in: %q, quoted: %s", s, quoted))
qt.Assert(t, qt.Equals(len(f.Stmts), 1), qt.Commentf("in: %q, quoted: %s", s, quoted))
call, ok := f.Stmts[0].Cmd.(*CallExpr)
qt.Assert(t, ok, qt.IsTrue, qt.Commentf("in: %q, quoted: %s", s, quoted))
qt.Assert(t, len(call.Args), qt.Equals, 1, qt.Commentf("in: %q, quoted: %s", s, quoted))
qt.Assert(t, qt.IsTrue(ok), qt.Commentf("in: %q, quoted: %s", s, quoted))
qt.Assert(t, qt.Equals(len(call.Args), 1), qt.Commentf("in: %q, quoted: %s", s, quoted))

// Also check that the single word only uses literals or quoted strings.
Walk(call.Args[0], func(node Node) bool {
Expand Down
11 changes: 6 additions & 5 deletions syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sync"
"testing"

qt "github.com/frankban/quicktest"
"github.com/go-quicktest/qt"
"github.com/google/go-cmp/cmp"
)

Expand Down Expand Up @@ -186,6 +186,7 @@ func requireBash52(tb testing.TB) {
tb.Skipf("bash 5.2 required to run")
}
}

func requireDash059(tb testing.TB) {
if !onceHasDash059() {
tb.Skipf("dash 0.5.9+ required to run")
Expand Down Expand Up @@ -2528,15 +2529,15 @@ func TestBackquotesPos(t *testing.T) {
in := "`\\\\foo`"
p := NewParser()
f, err := p.Parse(strings.NewReader(in), "")
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))
cmdSubst := f.Stmts[0].Cmd.(*CallExpr).Args[0].Parts[0].(*CmdSubst)
lit := cmdSubst.Stmts[0].Cmd.(*CallExpr).Args[0].Parts[0].(*Lit)

qt.Assert(t, lit.Value, qt.Equals, lit.Value)
qt.Assert(t, qt.Equals(lit.Value, lit.Value))
// Note that positions of literals with escape sequences inside backquote command substitutions
// are weird, since we effectively skip over the double escaping in the literal value and positions.
// Even though the input source has '\\foo' between columns 2 and 7 (length 5)
// we end up keeping '\foo' between columns 3 and 7 (length 4).
qt.Assert(t, lit.ValuePos.String(), qt.Equals, "1:2")
qt.Assert(t, lit.ValueEnd.String(), qt.Equals, "1:7")
qt.Assert(t, qt.Equals(lit.ValuePos.String(), "1:2"))
qt.Assert(t, qt.Equals(lit.ValueEnd.String(), "1:7"))
}
10 changes: 5 additions & 5 deletions syntax/quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package syntax
import (
"testing"

qt "github.com/frankban/quicktest"
"github.com/go-quicktest/qt"
)

func TestQuote(t *testing.T) {
Expand Down Expand Up @@ -41,11 +41,11 @@ func TestQuote(t *testing.T) {
got, gotErr := Quote(test.str, test.lang)
switch want := test.want.(type) {
case string:
qt.Assert(t, got, qt.Equals, want)
qt.Assert(t, gotErr, qt.IsNil)
qt.Assert(t, qt.Equals(got, want))
qt.Assert(t, qt.IsNil(gotErr))
case *QuoteError:
qt.Assert(t, got, qt.Equals, "")
qt.Assert(t, gotErr, qt.DeepEquals, want)
qt.Assert(t, qt.Equals(got, ""))
qt.Assert(t, qt.DeepEquals(gotErr, error(want)))
default:
t.Fatalf("unexpected type: %T", want)
}
Expand Down
30 changes: 15 additions & 15 deletions syntax/typedjson/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
"testing"

qt "github.com/frankban/quicktest"
"github.com/go-quicktest/qt"

"mvdan.cc/sh/v3/syntax"
"mvdan.cc/sh/v3/syntax/typedjson"
Expand All @@ -24,7 +24,7 @@ func TestRoundtrip(t *testing.T) {

dir := filepath.Join("testdata", "roundtrip")
shellPaths, err := filepath.Glob(filepath.Join(dir, "*.sh"))
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))
for _, shellPath := range shellPaths {

shellPath := shellPath // do not reuse the range var
Expand All @@ -34,55 +34,55 @@ func TestRoundtrip(t *testing.T) {
t.Parallel()

shellInput, err := os.ReadFile(shellPath)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))
jsonInput, err := os.ReadFile(jsonPath)
if !*update { // allow it to not exist
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))
}
sb := new(strings.Builder)

// Parse the shell source and check that it is well formatted.
parser := syntax.NewParser(syntax.KeepComments(true))
node, err := parser.Parse(bytes.NewReader(shellInput), "")
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))

printer := syntax.NewPrinter()
sb.Reset()
err = printer.Print(sb, node)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, sb.String(), qt.Equals, string(shellInput))
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.Equals(sb.String(), string(shellInput)))

// Validate writing the pretty JSON.
sb.Reset()
encOpts := typedjson.EncodeOptions{Indent: "\t"}
err = encOpts.Encode(sb, node)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))
got := sb.String()
if *update {
err := os.WriteFile(jsonPath, []byte(got), 0o666)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))
} else {
qt.Assert(t, got, qt.Equals, string(jsonInput))
qt.Assert(t, qt.Equals(got, string(jsonInput)))
}

// Ensure we don't use the originally parsed node again.
node = nil

// Validate reading the pretty JSON and check that it formats the same.
node2, err := typedjson.Decode(bytes.NewReader(jsonInput))
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))

sb.Reset()
err = printer.Print(sb, node2)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, sb.String(), qt.Equals, string(shellInput))
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.Equals(sb.String(), string(shellInput)))

// Validate that emitting the JSON again produces the same result.
sb.Reset()
err = encOpts.Encode(sb, node2)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, qt.IsNil(err))
got = sb.String()
qt.Assert(t, got, qt.Equals, string(jsonInput))
qt.Assert(t, qt.Equals(got, string(jsonInput)))
})
}
}

0 comments on commit 0763f7d

Please sign in to comment.