From 8bb05ac73a5b448b339ce0bc8d396c82c459b47f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 21:33:32 +0200 Subject: Merging upstream version 2.40. Signed-off-by: Daniel Baumann --- tests/ts/libsmartcols/continuous-json | 28 ++++ tests/ts/libsmartcols/files/col-bool | 1 + tests/ts/libsmartcols/files/col-float | 1 + tests/ts/libsmartcols/files/col-hidden | 4 +- tests/ts/libsmartcols/files/col-id | 4 +- tests/ts/libsmartcols/files/col-name | 4 +- tests/ts/libsmartcols/files/col-noextremes | 4 +- tests/ts/libsmartcols/files/col-number | 4 +- tests/ts/libsmartcols/files/col-parent | 4 +- tests/ts/libsmartcols/files/col-strict | 4 +- tests/ts/libsmartcols/files/col-string | 4 +- tests/ts/libsmartcols/files/col-tree | 4 +- tests/ts/libsmartcols/files/col-trunc | 4 +- tests/ts/libsmartcols/files/col-wrap | 4 +- tests/ts/libsmartcols/files/col-wrapnl | 4 +- tests/ts/libsmartcols/files/col-wrapzero | 1 + tests/ts/libsmartcols/files/data-bool | 10 ++ tests/ts/libsmartcols/files/data-float | 10 ++ tests/ts/libsmartcols/files/data-string-nl | 10 +- tests/ts/libsmartcols/files/data-string-zero | 10 ++ tests/ts/libsmartcols/filter | 217 +++++++++++++++++++++++++++ tests/ts/libsmartcols/fromfile | 26 ++++ 22 files changed, 321 insertions(+), 41 deletions(-) create mode 100755 tests/ts/libsmartcols/continuous-json create mode 100644 tests/ts/libsmartcols/files/col-bool create mode 100644 tests/ts/libsmartcols/files/col-float create mode 100644 tests/ts/libsmartcols/files/col-wrapzero create mode 100644 tests/ts/libsmartcols/files/data-bool create mode 100644 tests/ts/libsmartcols/files/data-float create mode 100644 tests/ts/libsmartcols/files/data-string-zero create mode 100755 tests/ts/libsmartcols/filter (limited to 'tests/ts/libsmartcols') diff --git a/tests/ts/libsmartcols/continuous-json b/tests/ts/libsmartcols/continuous-json new file mode 100755 index 0000000..8456d6b --- /dev/null +++ b/tests/ts/libsmartcols/continuous-json @@ -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_CONTINUOUS_JSON" +ts_check_test_command "$TESTPROG" + +ts_run $TESTPROG --width 80 >> $TS_OUTPUT 2>> $TS_ERRLOG + +ts_finalize diff --git a/tests/ts/libsmartcols/files/col-bool b/tests/ts/libsmartcols/files/col-bool new file mode 100644 index 0000000..c3324e8 --- /dev/null +++ b/tests/ts/libsmartcols/files/col-bool @@ -0,0 +1 @@ +name=BOOL,right,type=boolean,json=boolean diff --git a/tests/ts/libsmartcols/files/col-float b/tests/ts/libsmartcols/files/col-float new file mode 100644 index 0000000..7069dc7 --- /dev/null +++ b/tests/ts/libsmartcols/files/col-float @@ -0,0 +1 @@ +name=NUM,right,type=float,json=float diff --git a/tests/ts/libsmartcols/files/col-hidden b/tests/ts/libsmartcols/files/col-hidden index 83182a8..9bbb15f 100644 --- a/tests/ts/libsmartcols/files/col-hidden +++ b/tests/ts/libsmartcols/files/col-hidden @@ -1,3 +1 @@ -FOO -0 -hidden +name=FOO,hidden diff --git a/tests/ts/libsmartcols/files/col-id b/tests/ts/libsmartcols/files/col-id index 0188f42..8a800fc 100644 --- a/tests/ts/libsmartcols/files/col-id +++ b/tests/ts/libsmartcols/files/col-id @@ -1,3 +1 @@ -ID -0 -right +name=ID,right,type=number,json=number diff --git a/tests/ts/libsmartcols/files/col-name b/tests/ts/libsmartcols/files/col-name index 0a98f29..4fed26f 100644 --- a/tests/ts/libsmartcols/files/col-name +++ b/tests/ts/libsmartcols/files/col-name @@ -1,3 +1 @@ -NAME -0 -none +name=NAME diff --git a/tests/ts/libsmartcols/files/col-noextremes b/tests/ts/libsmartcols/files/col-noextremes index 715edce..7df2e2f 100644 --- a/tests/ts/libsmartcols/files/col-noextremes +++ b/tests/ts/libsmartcols/files/col-noextremes @@ -1,3 +1 @@ -NOEXTREME -0 -noextremes +name=NOEXTREME,noextremes diff --git a/tests/ts/libsmartcols/files/col-number b/tests/ts/libsmartcols/files/col-number index 34a70e4..0f880ff 100644 --- a/tests/ts/libsmartcols/files/col-number +++ b/tests/ts/libsmartcols/files/col-number @@ -1,3 +1 @@ -NUM -0 -right +name=NUM,right,type=number,json=number diff --git a/tests/ts/libsmartcols/files/col-parent b/tests/ts/libsmartcols/files/col-parent index 86fe08c..be25a82 100644 --- a/tests/ts/libsmartcols/files/col-parent +++ b/tests/ts/libsmartcols/files/col-parent @@ -1,3 +1 @@ -PARENT -0 -right +name=PARENT,right,type=number diff --git a/tests/ts/libsmartcols/files/col-strict b/tests/ts/libsmartcols/files/col-strict index 62bb96b..8381f92 100644 --- a/tests/ts/libsmartcols/files/col-strict +++ b/tests/ts/libsmartcols/files/col-strict @@ -1,3 +1 @@ -STRICT -20 -strictwidth,right +name=STRICT,strictwidth,right,width=20 diff --git a/tests/ts/libsmartcols/files/col-string b/tests/ts/libsmartcols/files/col-string index 7e2904b..e96c37f 100644 --- a/tests/ts/libsmartcols/files/col-string +++ b/tests/ts/libsmartcols/files/col-string @@ -1,3 +1 @@ -STRINGS -0 -none +name=STRINGS diff --git a/tests/ts/libsmartcols/files/col-tree b/tests/ts/libsmartcols/files/col-tree index 5076880..6c69ca0 100644 --- a/tests/ts/libsmartcols/files/col-tree +++ b/tests/ts/libsmartcols/files/col-tree @@ -1,3 +1 @@ -TREE -0 -tree +name=TREE,tree diff --git a/tests/ts/libsmartcols/files/col-trunc b/tests/ts/libsmartcols/files/col-trunc index 2887b43..55c9a70 100644 --- a/tests/ts/libsmartcols/files/col-trunc +++ b/tests/ts/libsmartcols/files/col-trunc @@ -1,3 +1 @@ -TRUNC -0 -trunc +name=TRUNC,trunc diff --git a/tests/ts/libsmartcols/files/col-wrap b/tests/ts/libsmartcols/files/col-wrap index dc4ca34..c8e622d 100644 --- a/tests/ts/libsmartcols/files/col-wrap +++ b/tests/ts/libsmartcols/files/col-wrap @@ -1,3 +1 @@ -WRAP -0 -wrap +name=WRAP,wrap diff --git a/tests/ts/libsmartcols/files/col-wrapnl b/tests/ts/libsmartcols/files/col-wrapnl index 0a18fd1..fcbc217 100644 --- a/tests/ts/libsmartcols/files/col-wrapnl +++ b/tests/ts/libsmartcols/files/col-wrapnl @@ -1,3 +1 @@ -WRAPNL -0 -wrapnl +name=WRAPNL,wrapnl diff --git a/tests/ts/libsmartcols/files/col-wrapzero b/tests/ts/libsmartcols/files/col-wrapzero new file mode 100644 index 0000000..b197014 --- /dev/null +++ b/tests/ts/libsmartcols/files/col-wrapzero @@ -0,0 +1 @@ +name=WRAPZERO,wrapzero diff --git a/tests/ts/libsmartcols/files/data-bool b/tests/ts/libsmartcols/files/data-bool new file mode 100644 index 0000000..d6bda92 --- /dev/null +++ b/tests/ts/libsmartcols/files/data-bool @@ -0,0 +1,10 @@ +0 +1 + +0 +true +false +FALSE +TRUE +0 +1 diff --git a/tests/ts/libsmartcols/files/data-float b/tests/ts/libsmartcols/files/data-float new file mode 100644 index 0000000..ead3d90 --- /dev/null +++ b/tests/ts/libsmartcols/files/data-float @@ -0,0 +1,10 @@ +0 +100 +100.5 +99.9 +411 +5111 +678993321 +7666666 +8000 +8000.5 diff --git a/tests/ts/libsmartcols/files/data-string-nl b/tests/ts/libsmartcols/files/data-string-nl index 7822e57..ef16a72 100644 --- a/tests/ts/libsmartcols/files/data-string-nl +++ b/tests/ts/libsmartcols/files/data-string-nl @@ -1,10 +1,10 @@ aaa bbbbb -cccc\nCCCC -dddddddd\nDDDD\nDD -hello\nbaby -aaa\nbbb\nccc\nddd +cccc\x0ACCCC +dddddddd\x0ADDDD\x0ADD +hello\x0Ababy +aaa\x0Abbb\x0Accc\x0Addd eee fffff -g\nhhhhh +g\x0Ahhhhh ppppppppp diff --git a/tests/ts/libsmartcols/files/data-string-zero b/tests/ts/libsmartcols/files/data-string-zero new file mode 100644 index 0000000..5f936f1 --- /dev/null +++ b/tests/ts/libsmartcols/files/data-string-zero @@ -0,0 +1,10 @@ +aaa +bbbbb +cccc\x00CCCC +dddddddd\x00DDDD\x00DD +hello\x00baby +aaa\x00bbb\x00ccc\x00ddd +eee +fffff +g\x00hhhhh +ppppppppp diff --git a/tests/ts/libsmartcols/filter b/tests/ts/libsmartcols/filter new file mode 100755 index 0000000..2025ef5 --- /dev/null +++ b/tests/ts/libsmartcols/filter @@ -0,0 +1,217 @@ +#!/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="fromfile" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +TESTPROG="$TS_HELPER_LIBSMARTCOLS_FROMFILE" +ts_check_test_command "$TESTPROG" + +### Number +# +prefix="number" +declare -A FILTERS + +FILTERS["is"]='NUM' +FILTERS["neg"]='!NUM' +FILTERS["and"]='NUM && NAME' +FILTERS["or"]='NUM || NAME' + +FILTERS["eq"]='NUM == 100' +FILTERS["ne"]='NUM != 100' + +FILTERS["gt"]='NUM > 8000' +FILTERS["ge"]='NUM >= 100' +FILTERS["lt"]='NUM < 100' +FILTERS["le"]='NUM <= 100' + +FILTERS["expr-and-expr"]='NUM > 10 && NUM < 8000' +FILTERS["expr-or-expr"]='NUM == 3 || NUM == 100' +FILTERS["and-or"]='(NUM >= 3 && NUM <= 100) || NUM == 0' + +FILTERS["as-string"]='NUM == "100"' + +printf '%s\n' "${!FILTERS[@]}" | sort | while read name; do + ts_init_subtest "$prefix-$name" + echo "expr: ${FILTERS[$name]}" >> $TS_OUTPUT + echo >> $TS_OUTPUT + ts_run $TESTPROG --nlines 10 --width 80 \ + --filter "${FILTERS[$name]}" \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-number \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-number \ + >> $TS_OUTPUT 2> /dev/null + ts_finalize_subtest +done +FILTERS=() + + +### Float +# +prefix="float" +declare -A FILTERS + +FILTERS["is"]='NUM' +FILTERS["neg"]='!NUM' +FILTERS["and"]='NUM && NAME' +FILTERS["or"]='NUM || NAME' + +FILTERS["eq"]='NUM == 100' +FILTERS["eq2"]='NUM == 100.5' + +FILTERS["ne"]='NUM != 100' +FILTERS["ne2"]='NUM != 100.5' + +FILTERS["gt"]='NUM > 8000' +FILTERS["gt2"]='NUM > 8000.5' + +FILTERS["ge"]='NUM >= 100' +FILTERS["ge2"]='NUM >= 100.5' + +FILTERS["lt"]='NUM < 100' +FILTERS["lt2"]='NUM < 100.5' + +FILTERS["le"]='NUM <= 100' +FILTERS["le2"]='NUM <= 100.5' + +FILTERS["as-string"]='NUM == "100"' +FILTERS["as-string2"]='NUM == "100.5"' + +printf '%s\n' "${!FILTERS[@]}" | sort | while read name; do + ts_init_subtest "$prefix-$name" + echo "expr: ${FILTERS[$name]}" >> $TS_OUTPUT + echo >> $TS_OUTPUT + ts_run $TESTPROG --nlines 10 --width 80 \ + --filter "${FILTERS[$name]}" \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-float \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-float \ + >> $TS_OUTPUT 2> /dev/null + ts_finalize_subtest +done +FILTERS=() + +### Boolean +# +prefix="bool" +declare -A FILTERS + +FILTERS["is"]='BOOL' +FILTERS["neg"]='!BOOL' +FILTERS["and"]='BOOL && NAME' +FILTERS["or"]='BOOL || NAME' + +FILTERS["eq-true"]='BOOL == TRUE' +FILTERS["eq-true2"]='BOOL == true' +FILTERS["eq-true3"]='BOOL == 1' + +FILTERS["eq-false"]='BOOL == FALSE' +FILTERS["eq-false2"]='BOOL == false' +FILTERS["eq-false3"]='BOOL == 0' + +FILTERS["ne"]='BOOL != false' +FILTERS["ne2"]='BOOL != true' + +FILTERS["as-string"]='BOOL == "0"' +FILTERS["as-string2"]='BOOL == "1"' + +printf '%s\n' "${!FILTERS[@]}" | sort | while read name; do + ts_init_subtest "$prefix-$name" + echo "expr: ${FILTERS[$name]}" >> $TS_OUTPUT + echo >> $TS_OUTPUT + ts_run $TESTPROG --nlines 10 --width 80 \ + --filter "${FILTERS[$name]}" \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-bool \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-bool \ + >> $TS_OUTPUT 2> /dev/null + ts_finalize_subtest +done +FILTERS=() + + +### Strings +# +prefix="string" +declare -A FILTERS + +FILTERS["is"]='NAME' +FILTERS["neg"]='!NAME' + +FILTERS["eq"]='NAME == "bbb"' +FILTERS["ne"]='NAME != "bbb"' + +FILTERS["gt"]='NAME > "bbb"' +FILTERS["ge"]='NAME >= "bbb"' +FILTERS["lt"]='NAME < "bbb"' +FILTERS["le"]='NAME <= "bbb"' + +FILTERS["reg"]='NAME =~ "aaa.*"' +FILTERS["nreg"]='NAME !~ "aaa.*"' + +printf '%s\n' "${!FILTERS[@]}" | sort | while read name; do + ts_init_subtest "$prefix-$name" + echo "expr: ${FILTERS[$name]}" >> $TS_OUTPUT + echo >> $TS_OUTPUT + ts_run $TESTPROG --nlines 10 --width 80 \ + --filter "${FILTERS[$name]}" \ + --column $TS_SELF/files/col-name \ + $TS_SELF/files/data-string \ + >> $TS_OUTPUT 2> /dev/null + ts_finalize_subtest +done +FILTERS=() + + +### Broken +# +prefix="broken" +declare -A FILTERS + +FILTERS["no-start"]='NUM == 100)' +FILTERS["no-close"]='(NUM == 100' +FILTERS["no-column"]=' == 100' +FILTERS["no-param"]='NUM == ' +FILTERS["bad-oper"]='NUM ** 100' +FILTERS["bad-oper2"]='NUM = 100' +FILTERS["bad-column"]='XXX == 100' +FILTERS["bad-number"]='NUM == 1y0' +FILTERS["bad-float"]='NUM == 100 . 5' + +printf '%s\n' "${!FILTERS[@]}" | sort | while read name; do + ts_init_subtest "$prefix-$name" + echo "expr: ${FILTERS[$name]}" >> $TS_OUTPUT + echo >> $TS_OUTPUT + ts_run $TESTPROG --nlines 10 --width 80 \ + --filter "${FILTERS[$name]}" \ + --column $TS_SELF/files/col-number \ + $TS_SELF/files/data-number \ + 2>> $TS_OUTPUT 1> /dev/null + + sed -i -e 's/syntax error.*//g' $TS_OUTPUT + ts_finalize_subtest +done +FILTERS=() + + +ts_log "...done." +ts_finalize diff --git a/tests/ts/libsmartcols/fromfile b/tests/ts/libsmartcols/fromfile index 45b8471..c11140c 100755 --- a/tests/ts/libsmartcols/fromfile +++ b/tests/ts/libsmartcols/fromfile @@ -249,6 +249,32 @@ ts_run $TESTPROG --nlines 10 \ >> $TS_OUTPUT 2>> $TS_ERRLOG ts_finalize_subtest +ts_init_subtest "wrapzero" +ts_run $TESTPROG --nlines 10 \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-number \ + --column $TS_SELF/files/col-wrapzero \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-number \ + $TS_SELF/files/data-string-zero \ + >> $TS_OUTPUT 2>> $TS_ERRLOG +ts_finalize_subtest + +ts_init_subtest "wrapzero-tree" +ts_run $TESTPROG --nlines 10 \ + --tree-id-column 1 \ + --tree-parent-column 2 \ + --column $TS_SELF/files/col-tree \ + --column $TS_SELF/files/col-id \ + --column $TS_SELF/files/col-parent \ + --column $TS_SELF/files/col-wrapzero \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-id \ + $TS_SELF/files/data-parent \ + $TS_SELF/files/data-string-zero \ + >> $TS_OUTPUT 2>> $TS_ERRLOG +ts_finalize_subtest + ts_init_subtest "raw" ts_run $TESTPROG --nlines 10 --raw \ --column $TS_SELF/files/col-name \ -- cgit v1.2.3