]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add libsmartcols title test
authorKarel Zak <kzak@redhat.com>
Wed, 14 Sep 2016 10:49:46 +0000 (12:49 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 14 Sep 2016 10:49:46 +0000 (12:49 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/samples/Makemodule.am
libsmartcols/samples/fromfile.c
libsmartcols/samples/title.c
tests/commands.sh
tests/expected/libsmartcols/title [new file with mode: 0644]
tests/ts/libsmartcols/title [new file with mode: 0755]

index b44d888b42b712a7e8810469259c0218f9e40a66..0a54abbbf26dde330e7ee618ae8ed9d65a960084 100644 (file)
@@ -18,7 +18,7 @@ sample_scols_tree_CFLAGS = $(sample_scols_cflags)
 endif
 
 sample_scols_title_SOURCES = libsmartcols/samples/title.c
-sample_scols_title_LDADD = $(sample_scols_ldadd)
+sample_scols_title_LDADD = $(sample_scols_ldadd) libcommon.la
 sample_scols_title_CFLAGS = $(sample_scols_cflags)
 
 sample_scols_wrap_SOURCES = libsmartcols/samples/wrap.c
index ec12267a686f4d20481bb4dfb6b54bef49b8d422..aa283ded52c8670a36a3ef7bb0f373e412bd9969 100644 (file)
@@ -194,8 +194,6 @@ int main(int argc, char *argv[])
                        scols_table_set_termforce(tb, SCOLS_TERMFORCE_ALWAYS);
                        scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width"));
                        break;
-               default:
-                       err(EXIT_FAILURE, "%s [-r|--random]\n", program_invocation_short_name);
                }
        }
 
index 08cc2c62171da11b0dc6bafb3e470187c05b8285..85231609565b44f4fe77ad3a24b57de4f028f191 100644 (file)
@@ -57,6 +57,13 @@ int main(int argc, char *argv[])
        struct libscols_table *tb;
        struct libscols_symbols *sy;
        struct libscols_cell *title;
+       int c;
+
+       static const struct option longopts[] = {
+               { "maxout", 0, 0, 'm' },
+               { "width",  1, 0, 'w' },
+               { NULL, 0, 0, 0 },
+       };
 
        setlocale(LC_ALL, "");  /* just to have enable UTF8 chars */
 
@@ -66,6 +73,18 @@ int main(int argc, char *argv[])
        if (!tb)
                err(EXIT_FAILURE, "failed to create output table");
 
+       while((c = getopt_long(argc, argv, "mw:", longopts, NULL)) != -1) {
+               switch(c) {
+               case 'm':
+                       scols_table_enable_maxout(tb, TRUE);
+                       break;
+               case 'w':
+                       scols_table_set_termforce(tb, SCOLS_TERMFORCE_ALWAYS);
+                       scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width"));
+                       break;
+               }
+       }
+
        scols_table_enable_colors(tb, isatty(STDOUT_FILENO));
        setup_columns(tb);
        add_line(tb, "foo", "bla bla bla");
index 102711c516e31178541a224187f60f9a1a35471d..b20e6f587521333d11cab75eea17802482c8650e 100644 (file)
@@ -17,6 +17,7 @@ TS_HELPER_LIBMOUNT_UPDATE="$top_builddir/test_mount_tab_update"
 TS_HELPER_LIBMOUNT_UTILS="$top_builddir/test_mount_utils"
 TS_HELPER_LIBMOUNT_DEBUG="$top_builddir/test_mount_debug"
 TS_HELPER_LIBSMARTCOLS_FROMFILE="$top_builddir/sample-scols-fromfile"
+TS_HELPER_LIBSMARTCOLS_TITLE="$top_builddir/sample-scols-title"
 TS_HELPER_PYLIBMOUNT_CONTEXT="$top_srcdir/libmount/python/test_mount_context.py"
 TS_HELPER_PYLIBMOUNT_TAB="$top_srcdir/libmount/python/test_mount_tab.py"
 TS_HELPER_PYLIBMOUNT_UPDATE="$top_srcdir/libmount/python/test_mount_tab_update.py"
diff --git a/tests/expected/libsmartcols/title b/tests/expected/libsmartcols/title
new file mode 100644 (file)
index 0000000..b5f4c12
--- /dev/null
@@ -0,0 +1,12 @@
+                                                             This is right title
+NAME DATA
+foo  bla bla bla
+bar  alb alb alb
+=======================This is center title (with padding)======================
+NAME DATA
+foo  bla bla bla
+bar  alb alb alb
+This is left title (with padding)-----------------------------------------------
+NAME DATA
+foo  bla bla bla
+bar  alb alb alb
diff --git a/tests/ts/libsmartcols/title b/tests/ts/libsmartcols/title
new file mode 100755 (executable)
index 0000000..a9ba6a4
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="title"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+TESTPROG="$TS_HELPER_LIBSMARTCOLS_TITLE"
+ts_check_test_command "$TESTPROG"
+
+$TESTPROG --width 80 >> $TS_OUTPUT 2>&1
+
+ts_finalize