Attempt to reproduce #154

This commit is contained in:
Neale Pickett 2020-11-02 08:21:19 -08:00
parent e771ae88c1
commit 8bc5dfd784
3 changed files with 66 additions and 0 deletions

View File

@ -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())
}
}

38
cmd/transpile/testdata/cat1/1/mkpuzzle vendored Executable file
View File

@ -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

8
cmd/transpile/testdata/cat1/1/moo.txt vendored Normal file
View File

@ -0,0 +1,8 @@
______
< moo. >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||