Skip to content

Commit

Permalink
Merge pull request #119 from yassinebenaid/dev
Browse files Browse the repository at this point in the history
`e2e`: cover more redirection cases & add support for test filtering
  • Loading branch information
yassinebenaid authored Jan 19, 2025
2 parents 44eee9e + 426044b commit e096756
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bunster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var dump = (&godump.Dumper{
}).Sprintln

func TestBunster(t *testing.T) {
filter := os.Getenv("FILTER")

buildWorkdir, err := prepareBuildAssets()
if err != nil {
t.Fatalf("Failed to prepare the build assets, %v", err)
Expand All @@ -52,6 +54,8 @@ func TestBunster(t *testing.T) {
t.Fatalf("Failed to `Glob` test files, %v", err)
}

var testsHasRan int // number of tests that has ran

for _, testFile := range testFiles {
t.Run(testFile, func(t *testing.T) {
testContent, err := os.ReadFile(testFile)
Expand All @@ -66,6 +70,12 @@ func TestBunster(t *testing.T) {
}

for i, testCase := range test.Cases {
if !strings.Contains(testCase.Name, filter) {
// we support filtering, someone would want to run specific tests.
continue
}
testsHasRan++

workdir, err := setupWorkdir()
if err != nil {
t.Fatalf("Failed to setup test workdir, %v", err)
Expand Down Expand Up @@ -134,6 +144,10 @@ func TestBunster(t *testing.T) {
}
})
}

if testsHasRan == 0 {
t.Fatalf("\nNo tests has ran.")
}
}

func buildBinary(workdir string, s []byte) (string, error) {
Expand Down
31 changes: 31 additions & 0 deletions tests/01-redirections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,34 @@ cases:
stderr: "redirected to stderr\n"
files:
"file.txt": "Hello World\n"

- name: "`<&` file descriptor duplication"
files:
"file.txt": "Hello World"
script: |
# duplicate the standard io
cat 3<<<'foobar' <&3
# duplicate an open file
cat 3<file.txt <&3
# redundant duplication
cat 3<file.txt 4<&3 0<&4
expect:
stdout: "foobar\nHello WorldHello World"
files:
"file.txt": "Hello World"

- name: "`<>` open file for reading and writing"
files:
"file.txt": "Hello World"
script: |
# read from
cat <>file.txt
# write to
cat <<<foobar 3<>file.txt >&3
expect:
stdout: "Hello World"
files:
"file.txt": "foobar\norld" # the 'W' character was removed because the content was overriden without truncation

0 comments on commit e096756

Please sign in to comment.