]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add columns separator to libsmartcols test
authorKarel Zak <kzak@redhat.com>
Fri, 16 Sep 2016 12:18:01 +0000 (14:18 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Sep 2016 12:18:01 +0000 (14:18 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/samples/fromfile.c
tests/expected/libsmartcols/fromfile-column-separator [new file with mode: 0644]
tests/ts/libsmartcols/fromfile

index 6b9748897beb8347c526e2a48cb49f3377021406..6d4ee4aafe2448ae903751e5bc89e8a081fc135f 100644 (file)
@@ -197,7 +197,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(" -n, --nlines <num>             number of lines\n", out);
        fputs(" -J, --json                     JSON output format\n", out);
        fputs(" -r, --raw                      RAW output format\n", out);
-       fputs(" -E, --export                   use key=\"value\" output format\n", out); 
+       fputs(" -E, --export                   use key=\"value\" output format\n", out);
+       fputs(" -C, --colsep <str>             set columns separator\n", out);
        fputs(" -w, --width <num>              hardcode terminal width\n", out);
        fputs(" -p, --tree-parent-column <n>   parent column\n", out);
        fputs(" -i, --tree-id-column <n>       id column\n", out);
@@ -223,6 +224,7 @@ int main(int argc, char *argv[])
                { "json",   0, 0, 'J' },
                { "raw",    0, 0, 'r' },
                { "export", 0, 0, 'E' },
+               { "colsep",  1, 0, 'C' },
                { "help",   0, 0, 'h' },
                { NULL, 0, 0, 0 },
        };
@@ -240,7 +242,7 @@ int main(int argc, char *argv[])
        if (!tb)
                err(EXIT_FAILURE, "failed to create output table");
 
-       while((c = getopt_long(argc, argv, "hc:Ei:Jmn:p:rw:", longopts, NULL)) != -1) {
+       while((c = getopt_long(argc, argv, "hCc:Ei:Jmn:p:rw:", longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
 
@@ -278,6 +280,9 @@ int main(int argc, char *argv[])
                case 'E':
                        scols_table_enable_export(tb, TRUE);
                        break;
+               case 'C':
+                       scols_table_set_column_separator(tb, optarg);
+                       break;
                case 'n':
                        nlines = strtou32_or_err(optarg, "failed to parse number of lines");
                        break;
diff --git a/tests/expected/libsmartcols/fromfile-column-separator b/tests/expected/libsmartcols/fromfile-column-separator
new file mode 100644 (file)
index 0000000..8c5aa2a
--- /dev/null
@@ -0,0 +1,11 @@
+NAME  |      NUM|TRUNC
+aaaa  |        0|qqqqqqqqqqqqqqqqqX
+bbb   |      100|dddddddddddddX
+ccccc |       21|ffffffffffffffffffffffffffffffffffffffffX
+dddddd|        3|ssssssssssX
+ee    |      411|ddddddddddddddddddddddddddX
+ffff  |     5111|jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjX
+gggggg|678993321|mmmmmmmmmmmmmmmmmmmX
+hhh   |  7666666|lllllllllllllllllllllllllllllllllllllX
+iiiiii|     8765|yyyyyyyyyyyyyyyyyyyyyyyyyyyyX
+jj    |   987456|pppppppppX
index c2796f777bcb91422e70ab165081f99a2cfcf929..a2a67f53d28298ba83ccbd04120f8148332627ce 100755 (executable)
@@ -85,7 +85,7 @@ ts_finalize_subtest
 
 ts_init_subtest "trunc"
 $TESTPROG --nlines 10 --width 40 \
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-number \
        --column $TS_SELF/files/col-trunc \
        $TS_SELF/files/data-string \
@@ -96,7 +96,7 @@ ts_finalize_subtest
 
 ts_init_subtest "right"
 $TESTPROG --nlines 10 \
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-number \
        --column $TS_SELF/files/col-string \
        $TS_SELF/files/data-string \
@@ -107,7 +107,7 @@ ts_finalize_subtest
 
 ts_init_subtest "right-maxout"
 $TESTPROG --nlines 10 --maxout --width 80\
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-number \
        $TS_SELF/files/data-string \
        $TS_SELF/files/data-number \
@@ -116,7 +116,7 @@ ts_finalize_subtest
 
 ts_init_subtest "strictwidth"
 $TESTPROG --nlines 10 \
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-strict \
        --column $TS_SELF/files/col-number \
        $TS_SELF/files/data-string \
@@ -127,7 +127,7 @@ ts_finalize_subtest
 
 ts_init_subtest "noextremes"
 $TESTPROG --nlines 10 --width 45 \
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-noextremes \
        --column $TS_SELF/files/col-number \
        --column $TS_SELF/files/col-name \
@@ -142,7 +142,7 @@ ts_finalize_subtest
 
 ts_init_subtest "hidden"
 $TESTPROG --nlines 10 \
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-hidden \
        --column $TS_SELF/files/col-number \
        $TS_SELF/files/data-string \
@@ -205,7 +205,7 @@ ts_finalize_subtest
 
 ts_init_subtest "raw"
 $TESTPROG --nlines 10 --raw \
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-number \
        --column $TS_SELF/files/col-trunc \
        $TS_SELF/files/data-string \
@@ -216,7 +216,18 @@ ts_finalize_subtest
 
 ts_init_subtest "export"
 $TESTPROG --nlines 10 --export \
-               --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-name \
+       --column $TS_SELF/files/col-number \
+       --column $TS_SELF/files/col-trunc \
+       $TS_SELF/files/data-string \
+       $TS_SELF/files/data-number \
+       $TS_SELF/files/data-string-long \
+       >> $TS_OUTPUT 2>&1
+ts_finalize_subtest
+
+ts_init_subtest "column-separator"
+$TESTPROG --nlines 10 --colsep \| \
+       --column $TS_SELF/files/col-name \
        --column $TS_SELF/files/col-number \
        --column $TS_SELF/files/col-trunc \
        $TS_SELF/files/data-string \