Skip to content

Commit

Permalink
interp: make all tests pass on Wine
Browse files Browse the repository at this point in the history
In other words, make the tests pass on a plain Windows setup.

First, we replaced simple uses of coreutils 'touch foo' with their
native Bash counterparts, like '>foo'.

Then, we made the test binary behave like a very simple cmd/gosh, so
that we can use our own available shell instead of 'bash -c'. We also
removed all assumptions that bash is installed.

Some coreutils cannot be replaced with builtins, such as mkdir or rm.
Implement very simple versions of those as a ModuleExec for the
interpreter that runs the tests.

Finally, some tests were just not possible to run on plain Windows, like
creating a directory named '*'. Split some tests between Unix-like and
Windows.
  • Loading branch information
mvdan committed Feb 17, 2019
1 parent b42aebd commit 9aa7c7f
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 90 deletions.
19 changes: 7 additions & 12 deletions interp/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package interp_test

import (
"context"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -35,27 +36,21 @@ func Example() {
}

func ExampleModuleExec() {
src := `
ls example_test.* || echo "ls failed"
rm example_test.* || echo "rm failed"
`
src := "echo foo; missing-program bar"
file, _ := syntax.NewParser().Parse(strings.NewReader(src), "")
exec := func(ctx context.Context, path string, args []string) error {
switch args[0] {
case "ls":
// whitelist the "ls" program
return interp.DefaultExec(ctx, path, args)
default:
// refuse to run any other program
if path == "" {
fmt.Printf("%s is not installed\n", args[0])
return interp.ExitStatus(1)
}
return interp.DefaultExec(ctx, path, args)
}
runner, _ := interp.New(
interp.StdIO(nil, os.Stdout, os.Stdout),
interp.Module(interp.ModuleExec(exec)),
)
runner.Run(context.TODO(), file)
// Output:
// example_test.go
// rm failed
// foo
// missing-program is not installed
}
Loading

0 comments on commit 9aa7c7f

Please sign in to comment.