Skip to content

Commit

Permalink
Merge pull request #9 from dtcaciuc/errfile
Browse files Browse the repository at this point in the history
Remove .err file if test succeeds; enable -shell option.
  • Loading branch information
dtcaciuc authored Feb 25, 2022
2 parents 0a4429c + 02272f3 commit 81f26e6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/grill/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var opts = struct {
no: flags.Bool("no", false, "answer no to all questions (unsupported)"),
preserveEnv: flags.Bool("preserve-env", false, "don't reset common environment variables"),
keepTmpdir: flags.Bool("keep-tmpdir", false, "keep temporary directories"),
shell: flags.String("shell", "/bin/sh", "shell to use for running tests (unsupported)"),
shell: flags.String("shell", "/bin/sh", "shell to use for running tests"),
shellOpts: flags.String("shell-opts", "", "arguments to invoke shell with (unsupported)"),
xunitFile: flags.String("xunit-file", "", "path to write xUnit XML output (unsupported)"),
indent: flags.Int("indent", 2, "number of spaces to use for indentation (unsupported)"),
Expand Down
6 changes: 5 additions & 1 deletion cmd/grill/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Main(a []string, stdout, stderr io.Writer) int {
return 2
}

context, err := grill.DefaultTestContext("bash", stdout, stderr)
context, err := grill.DefaultTestContext(*opts.shell, stdout, stderr)
if err != nil {
log.Println(err)
return 1
Expand Down Expand Up @@ -89,6 +89,10 @@ func Main(a []string, stdout, stderr io.Writer) int {
if err := suite.WriteErr(); err != nil {
log.Println(err)
}
} else {
if err := suite.RemoveErr(); err != nil {
log.Println(err)
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/grill/grill.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ func (suite TestSuite) WriteErr() error {
return nil
}

// RemoveErr removes the matching .err file, if it exists.
func (suite TestSuite) RemoveErr() error {
if err := os.Remove(suite.Name + ".err"); err != nil && !os.IsNotExist(err) {
return err
}
return nil
}

// WriteReport writes out a report on the overall grill run.
//
// Setting quiet to true will hide the suite diffs
Expand Down
23 changes: 18 additions & 5 deletions tests/errfile.t
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@

$ cp $TESTDIR/errfile/*.t .
$ mkdir sub
$ echo ' $ true' > sub/pass.t
$ echo ' $ false' > sub/fail.t

$ grill pass.t >/dev/null 2>&1

$ grill fail.t >/dev/null 2>&1
$ grill -quiet sub/*.t
!.
# Ran 2 tests, 0 skipped, 1 failed.
[1]

Error files are written out only for failed suites.

$ ls
$ ls sub/
fail.t
fail.t.err
pass.t

If test starts passing, err file is removed

$ echo ' $ true' > sub/fail.t
$ grill -quiet sub/*.t
..
# Ran 2 tests, 0 skipped, 0 failed.

$ ls sub/
fail.t
pass.t
1 change: 0 additions & 1 deletion tests/errfile/fail.t

This file was deleted.

1 change: 0 additions & 1 deletion tests/errfile/pass.t

This file was deleted.

19 changes: 19 additions & 0 deletions tests/shell.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-shell option sets the interpreter used to run the test.

$ cat > check-sh.t <<EOF
> $ echo \$0
> /bin/sh (glob)
> EOF

$ cat > check-bash.t <<EOF
> $ echo \$0
> /bin/bash (glob)
> EOF

$ grill check-sh.t
.
# Ran 1 test, 0 skipped, 0 failed.

$ grill -shell=/bin/bash check-bash.t
.
# Ran 1 test, 0 skipped, 0 failed.

0 comments on commit 81f26e6

Please sign in to comment.