@cryptotaxi247 / kubo / commits / 58126c1c6

parse_test: improve tests with stdin enabled arg

Now also check that we get the right arguments from the parsing. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed May 2, 2015 at 04:50 UTC 58126c1c6ccd733c15170a1c9ce8536eff1e46f6
1 file changed +18 -14
commands/cli/parse_test.go
+18 -14
@@ -239,19 +239,23 @@ func TestArgumentParsing(t *testing.T) {
239 t.Fatal(err)
240 }
241
242 - _, _, _, err = Parse([]string{"stdinenabled", "value1", "value2"}, nil, rootCmd)
243 - if err != nil {
244 - t.Error("Should have passed")
245 - t.Fatal(err)
246 - }
247 - _, _, _, err = Parse([]string{"stdinenabled"}, fstdin, rootCmd)
248 - if err != nil {
249 - t.Error("Should have passed")
250 - t.Fatal(err)
251 - }
252 - _, _, _, err = Parse([]string{"stdinenabled", "value1"}, fstdin, rootCmd)
253 - if err != nil {
254 - t.Error("Should have passed")
255 - t.Fatal(err)
242 + test := func(cmd words, f *os.File, res words) {
243 + if f != nil {
244 + if _, err := f.Seek(0, os.SEEK_SET); err != nil {
245 + t.Fatal(err)
246 + }
247 + }
248 + req, _, _, err := Parse(cmd, f, rootCmd)
249 + if err != nil {
250 + t.Error("Command '%v' should have passed parsing", cmd)
251 + }
252 + if !sameWords(req.Arguments(), res) {
253 + t.Errorf("Arguments parsed from '%v' are not '%v'", cmd, res)
254 + }
255 }
256 +
257 + test([]string{"stdinenabled", "value1", "value2"}, nil, []string{"value1", "value2"})
258 + test([]string{"stdinenabled"}, fstdin, []string{"stdin1"})
259 + test([]string{"stdinenabled", "value1"}, fstdin, []string{"stdin1", "value1"})
260 + test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"stdin1", "value1", "value2"})
261 }