]> granicus.if.org Git - procps-ng/commitdiff
test: add lib/strutils check
authorSami Kerola <kerolasa@iki.fi>
Sun, 26 Feb 2012 12:31:18 +0000 (13:31 +0100)
committerCraig Small <csmall@enc.com.au>
Sat, 3 Mar 2012 07:36:29 +0000 (18:36 +1100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lib/strutils.c
testsuite/Makefile.am
testsuite/lib.test/strutils.exp [new file with mode: 0644]

index bfe2cd0b4554eed823cbb0d10bc97b5ebec41615..325e18c264f5cd0fcd11b20c29cf9990691012a6 100644 (file)
@@ -46,6 +46,13 @@ double strtod_or_err(const char *str, const char *errmesg)
 #ifdef TEST_PROGRAM
 int main(int argc, char *argv[])
 {
-       return EXIT_FAILURE;
+       if (argc < 2) {
+               error(EXIT_FAILURE, 0, "no arguments");
+       } else if (argc < 3) {
+               printf("%ld\n", strtol_or_err(argv[1], "strtol_or_err"));
+       } else {
+               printf("%lf\n", strtod_or_err(argv[2], "strtod_or_err"));
+       }
+       return EXIT_SUCCESS;
 }
 #endif                         /* TEST_PROGRAM */
index 3f79532349b2db0baabf20c956a92c17337eb177..62acfa647f01229dc96fcbfd42d609370dd2bec4 100644 (file)
@@ -34,6 +34,7 @@ EXTRA_DIST = \
        global-conf.exp \
     free.test/free.exp \
     kill.test/kill.exp \
+    lib.test/strutils.exp \
     pgrep.test/pgrep.exp \
     pkill.test/pkill.exp \
     pmap.test/pmap.exp \
diff --git a/testsuite/lib.test/strutils.exp b/testsuite/lib.test/strutils.exp
new file mode 100644 (file)
index 0000000..7afa8f7
--- /dev/null
@@ -0,0 +1,25 @@
+#
+# Testsuite for lib/strutils program
+#
+
+set teststr "${topdir}lib/test_strutils"
+
+set test "without argument"
+spawn $teststr
+expect_pass "$test" "test_strutils: no arguments"
+
+set test "test long"
+spawn $teststr 1
+expect_pass "$test" "1"
+
+set test "test long fail"
+spawn $teststr fail
+expect_pass "$test" "test_strutils: strtol_or_err: \'fail\'"
+
+set test "test double"
+spawn $teststr dummy 1.1
+expect_pass "$test" "1.100000"
+
+set test "test double fail"
+spawn $teststr dummy fail
+expect_pass "$test" "test_strutils: strtod_or_err: \'fail\'"