Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 
      3 [ -f testing.sh ] && . testing.sh
      4 
      5 #testing "name" "command" "result" "infile" "stdin"
      6 
      7 testing "(exit with error)" "seq 2> /dev/null || echo yes" "yes\n" "" ""
      8 testing "(exit with error)" "seq 1 2 3 4 2> /dev/null || echo yes" \
      9         "yes\n" "" ""
     10 testing "one argument" "seq 3" "1\n2\n3\n" "" ""
     11 testing "two arguments" "seq 5 7" "5\n6\n7\n" "" ""
     12 testing "two arguments reversed" "seq 7 5" "" "" ""
     13 testing "two arguments equal" "seq 3 3" "3\n" "" ""
     14 testing "two arguments equal, arbitrary negative step" "seq 1 -15 1" \
     15         "1\n" "" ""
     16 testing "two arguments equal, arbitrary positive step" "seq 1 +15 1" \
     17         "1\n" "" ""
     18 testing "count up by 2" "seq 4 2 8" "4\n6\n8\n" "" ""
     19 testing "count down by 2" "seq 8 -2 4" "8\n6\n4\n" "" ""
     20 testing "count wrong way #1" "seq 4 -2 8" "" "" ""
     21 testing "count wrong way #2" "seq 8 2 4" "" "" ""
     22 testing "count by .3" "seq 3 .3 4" "3.0\n3.3\n3.6\n3.9\n" "" ""
     23 testing "count by -.9" "seq .7 -.9 -2.2" "0.7\n-0.2\n-1.1\n-2.0\n" "" ""
     24 
     25 # Ubuntu does this, for no obvious reason. (The "yes" command exists.)
     26 #testing "count up by zero" "seq 4 0 8 | head -n 4" "4\n4\n4\n4\n" "" ""
     27 #testing "count nowhere by zero" "seq 4 0 4 | head -n 4" "4\n4\n4\n4\n" "" ""
     28 
     29 testing "count down by zero" "seq 8 0 4 | head -n 4" "" "" ""
     30 testing "separator -" "seq -s - 1 3" "1-2-3\n" "" ""
     31 testing "format string" 'seq -f %+01g -10 5 10' "-10\n-5\n+0\n+5\n+10\n" \
     32   "" ""
     33 testing "separator and format string" "seq -f \%03g -s \; 5 -1 0" "005;004;003;002;001;000\n" "" ""
     34 testing "padding" "seq -s, -w -2 19 120" "-02,017,036,055,074,093,112\n" \
     35   "" ""
     36 testing "padding" "seq -s, -w -2 3 12" "-2,01,04,07,10\n" "" ""
     37 testing "padding" "seq -s, -w -2.2 3.3 12" "-2.2,01.1,04.4,07.7,11.0\n" \
     38   "" ""
     39 
     40 # Test -f format filtering
     41 for i in %f %e %g "boo %f yah" "% f" %-1.2f %+-f "%+ - f" %.2f %3.f "%'.2f" \
     42 	%%%f%%
     43 do
     44   testing "filter -f \"$i\"" "seq -f \"$i\" 1 3 > /dev/null && echo yes" \
     45     "yes\n" "" ""
     46 done
     47 # Test -f format filtering failures
     48 for i in %d %s "" "boo %f %f yah" "%*f" %-1.2.3f '%2$f' %1-f "%1 f" \
     49 	%2..2f %%%f%%%
     50 do
     51   testing "filter reject -f '$i'" \
     52     "seq -f '$i' 1 3 2>/dev/null || echo no" "no\n" "" ""
     53 done
     54 
     55 testing "precision inc" "seq -s, 1.0 2.00 4" "1.00,3.00\n" "" ""
     56 testing "precision first" "seq -s, 1.000 2.0 4" "1.000,3.000\n" "" ""
     57 
     58 # In ubuntu inc and first set precision, but last doesn't. (Why?)
     59 #testing "precision last" "seq -s, 1.0 2.0 4.00" "1.0,3.0\n" "" ""
     60 
     61 testing "precision int" "seq -s, 9007199254740991 1 9007199254740991" \
     62   "9007199254740991\n" "" ""
     63 testing "precision e" "seq -s, 1.0e0 2" "1.0,2.0\n" "" ""
     64 testing "precision E" "seq -s, 1.0E0 2" "1.0,2.0\n" "" ""
     65 
     66 testing "invalid last" "seq 1 1 1f 2>/dev/null || echo y" "y\n" "" ""
     67 testing "invalid first" "seq 1f 1 1 2>/dev/null || echo y" "y\n" "" ""
     68 testing "invalid increment" "seq 1 1f 1 2>/dev/null || echo y" "y\n" "" ""
     69 
     70 # TODO: busybox fails this too, but GNU seems to not use double for large ints.
     71 #testing "too large for double" "seq -s, 9007199254740991 1 9007199254740992" "9007199254740992\n" "" ""
     72