-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtranscript_test.go
More file actions
57 lines (48 loc) · 1.19 KB
/
transcript_test.go
File metadata and controls
57 lines (48 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This file exercises the Go API.
// It's intentionally redundant with ./test.sh, which exercises the CLI.
package main_test
import (
"embed"
"io/fs"
"os"
"strings"
"testing"
"github.com/deref/transcript/cmdtest"
"github.com/stretchr/testify/assert"
)
//go:embed tests/*
var tests embed.FS
func TestTranscript(t *testing.T) {
// Save original directory
originalDir, err := os.Getwd()
if !assert.NoError(t, err) {
return
}
defer os.Chdir(originalDir)
err = fs.WalkDir(tests, "tests", func(path string, d fs.DirEntry, err error) error {
if !assert.NoError(t, err) {
return err
}
if d.IsDir() || !strings.HasSuffix(path, "test.cmdt") {
return nil
}
// Extract test directory from path (e.g., "tests/binary-output/test.cmdt" -> "tests/binary-output")
testDir := strings.TrimSuffix(path, "/test.cmdt")
f, err := tests.Open(path)
if !assert.NoError(t, err) {
return nil
}
defer f.Close()
t.Run("check:"+path, func(t *testing.T) {
// Change to the test directory before running the test
err := os.Chdir(testDir)
if !assert.NoError(t, err) {
return
}
defer os.Chdir(originalDir)
cmdtest.Check(t, f)
})
return nil
})
assert.NoError(t, err)
}