Commit 138c3951 authored by Christian Couder's avatar Christian Couder

parse_test: use fileToSimulateStdin()

License: MIT
Signed-off-by: default avatarChristian Couder <chriscool@tuxfamily.org>
parent 4cdea68b
...@@ -229,15 +229,18 @@ func TestArgumentParsing(t *testing.T) { ...@@ -229,15 +229,18 @@ func TestArgumentParsing(t *testing.T) {
} }
// Use a temp file to simulate stdin // Use a temp file to simulate stdin
fileToSimulateStdin := func(t *testing.T, content string) (*os.File) {
fstdin, err := ioutil.TempFile("", "") fstdin, err := ioutil.TempFile("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(fstdin.Name()) defer os.Remove(fstdin.Name())
if _, err := io.WriteString(fstdin, "stdin1"); err != nil { if _, err := io.WriteString(fstdin, content); err != nil {
t.Fatal(err) t.Fatal(err)
} }
return fstdin
}
test := func(cmd words, f *os.File, res words) { test := func(cmd words, f *os.File, res words) {
if f != nil { if f != nil {
...@@ -255,6 +258,9 @@ func TestArgumentParsing(t *testing.T) { ...@@ -255,6 +258,9 @@ func TestArgumentParsing(t *testing.T) {
} }
test([]string{"stdinenabled", "value1", "value2"}, nil, []string{"value1", "value2"}) test([]string{"stdinenabled", "value1", "value2"}, nil, []string{"value1", "value2"})
fstdin := fileToSimulateStdin(t, "stdin1")
test([]string{"stdinenabled"}, fstdin, []string{"stdin1"}) test([]string{"stdinenabled"}, fstdin, []string{"stdin1"})
test([]string{"stdinenabled", "value1"}, fstdin, []string{"stdin1", "value1"}) test([]string{"stdinenabled", "value1"}, fstdin, []string{"stdin1", "value1"})
test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"stdin1", "value1", "value2"}) test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"stdin1", "value1", "value2"})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment