-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli_test.go
61 lines (57 loc) · 1.46 KB
/
cli_test.go
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
58
59
60
61
package scripttool
import (
"io/fs"
"os"
"path"
"strings"
"testing"
)
var (
testdataBase = "testdata"
testoutBase = "testout"
)
func TestRunScripttool(t *testing.T) {
var verb string
appName := os.Args[0]
// Run the JSON command
if _, err := os.Stat(testoutBase); err == nil {
os.RemoveAll(testoutBase)
}
os.MkdirAll(testoutBase, 0775)
fSys := os.DirFS(testdataBase)
fs.WalkDir(fSys, ".", func(p string, info fs.DirEntry, err error) error {
if !info.IsDir() {
inName := info.Name()
inExt := path.Ext(inName)
outName := strings.TrimSuffix(inName, inExt) + ".json"
//fmt.Printf("DEBUG pth: %q fName: %q, ext: %q\n", p, inName, inExt)
switch inExt {
case ".txt":
verb = "fountain2json"
case ".fountain":
verb = "fountain2json"
case ".fdx":
verb = "fdx2json"
case ".fadein":
verb = "fadein2json"
case ".osf":
verb = "osf2json"
default:
// We're only doing
//fmt.Printf("Skipping %q, unsupported to file extension %q\n", inName, inExt)
return nil
}
// We'll just rely on our standard VERB INPUT_NAME OUTPUT_NAME
in := os.Stdin
out := os.Stdout
eout := os.Stderr
inputFName := path.Join(testdataBase, inName)
outputFName := path.Join(testoutBase, outName)
args := []string{appName, verb, inputFName, outputFName}
if err := RunScripttool(in, out, eout, args); err != nil {
t.Errorf("unexpected error RunScripttool(in, out, eout, %+v) -> %s", args, err)
}
}
return nil
})
}