diff --git a/cmd/transpile/main_test.go b/cmd/transpile/main_test.go index 5566018..af48f3b 100644 --- a/cmd/transpile/main_test.go +++ b/cmd/transpile/main_test.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/json" "io/ioutil" + "strings" "testing" "github.com/dirtbags/moth/pkg/transpile" @@ -163,3 +164,22 @@ func TestMothballs(t *testing.T) { } } } + +func TestFilesystem(t *testing.T) { + stdout := new(bytes.Buffer) + stderr := new(bytes.Buffer) + tp := T{ + Stdout: stdout, + Stderr: stderr, + BaseFs: afero.NewOsFs(), + } + + stdout.Reset() + if err := tp.Run("file", "-dir=testdata/cat1/1", "-file=moo.txt"); err != nil { + t.Error(err) + } + if !strings.Contains(stdout.String(), "Moo.") { + t.Error("Wrong file pulled", stdout.String()) + } + +} \ No newline at end of file diff --git a/cmd/transpile/testdata/cat1/1/mkpuzzle b/cmd/transpile/testdata/cat1/1/mkpuzzle new file mode 100755 index 0000000..e61b4a2 --- /dev/null +++ b/cmd/transpile/testdata/cat1/1/mkpuzzle @@ -0,0 +1,38 @@ +#! /bin/sh + +fail () { + echo "ERROR: $*" 1>&2 + exit 1 +} + +case $1:$2 in + puzzle:) + cat <<'EOT' +{ + "Answers": ["answer"], + "Pre": { + "Authors": ["neale"], + "Body": "I am a generated puzzle." + } +} +EOT + ;; + file:moo.txt) + echo "Moo." + ;; + file:*) + cat "$2" || exit 1 + ;; + answer:moo) + echo '{"Correct":true}' + ;; + answer:error) + fail "you requested an error" + ;; + answer:*) + echo '{"Correct":false}' + ;; + *) + fail "What is $1" + ;; +esac diff --git a/cmd/transpile/testdata/cat1/1/moo.txt b/cmd/transpile/testdata/cat1/1/moo.txt new file mode 100644 index 0000000..b4e62b9 --- /dev/null +++ b/cmd/transpile/testdata/cat1/1/moo.txt @@ -0,0 +1,8 @@ + ______ +< moo. > + ------ + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || ||