OSDN Git Service

Add seq -f tests, tweak help text, and catch one more error case.
authorRob Landley <rob@landley.net>
Sat, 5 Sep 2015 10:46:35 +0000 (05:46 -0500)
committerRob Landley <rob@landley.net>
Sat, 5 Sep 2015 10:46:35 +0000 (05:46 -0500)
tests/seq.test
toys/lsb/seq.c

index 3f3b409..4d23f8e 100755 (executable)
@@ -26,3 +26,17 @@ testing "seq separator -" "seq -s - 1 3" "1-2-3\n" "" ""
 testing "seq format string" 'seq -f %+01g -10 5 10' "-10\n-5\n+0\n+5\n+10\n" "" ""
 testing "seq separator and format string" "seq -f \%03g -s \; 5 -1 0" "005;004;003;002;001;000\n" "" ""
 
+# Test -f format filtering
+for i in %f %e %g "boo %f yah" "% f" %-1.2f %+-f "%+ - f" %.2f %3.f "%'.2f" \
+       %%%f%% %%%f%%%
+do
+  testing "seq filter -f \"$i\"" "seq -f \"$i\" 1 3 > /dev/null && echo yes" \
+    "yes\n" "" ""
+done
+# Test -f format filtering failures
+for i in %d %s "" "boo %f %f yah" "%*f" %-1.2.3f '%2$f' %1-f "%1 f" \
+       %2..2f
+do
+  testing "seq filter reject -f '$i'" \
+    "seq -f '$i' 1 3 2>/dev/null || echo no" "no\n" "" ""
+done
index 322940b..f1ca0d0 100644 (file)
@@ -17,7 +17,7 @@ config SEQ
     to 1. Two arguments are used as first and last. Arguments can be
     negative or floating point.
 
-    -f Use fmt_str as a floating point format string
+    -f Use fmt_str as a printf-style floating point format string
     -s Use sep_str as separator, default is a newline character
 */
 
@@ -47,7 +47,7 @@ static void insanitize(char *f)
   }
 
   // The @ is a byte offset, not utf8 chars. Waiting for somebody to complain...
-  if (*s) error_exit("bad -f '%s'@%d", f, s-f+1);
+  if (*s || !found) error_exit("bad -f '%s'@%d", f, s-f+1);
 }
 
 void seq_main(void)