tests: add libsmartcols title test

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2016-09-14 12:49:46 +02:00
parent 8fe4724568
commit 36eb51ebb4
6 changed files with 61 additions and 3 deletions

View 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

View 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);
}
}

View 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");

View 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"

View File

@ -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

28
tests/ts/libsmartcols/title Executable file
View File

@ -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