blob: 6fdc4dcf0851fc13ebfd55e32a7c25a1600de6a0 [file]
#!/usr/bin/env 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="json stream"
. "$TS_TOPDIR"/functions.sh
ts_init "$*"
TESTPROG="$TS_HELPER_LIBSMARTCOLS_CONTINUOUS_JSON"
ts_check_test_command "$TESTPROG"
# scols_table_print_range() prints the lines without the enclosing root object
# and array, so the output has to be a sequence of top-level JSON values; the
# objects are never comma separated, no matter if they are printed by one call
# (--batch) or by more calls.
for fmt in pretty compact lines; do
ts_init_subtest "batch-$fmt"
LIBSMARTCOLS_JSON="$fmt" ts_run "$TESTPROG" --batch 3 >> "$TS_OUTPUT" 2>> "$TS_ERRLOG"
ts_finalize_subtest
ts_init_subtest "stream-$fmt"
LIBSMARTCOLS_JSON="$fmt" ts_run "$TESTPROG" >> "$TS_OUTPUT" 2>> "$TS_ERRLOG"
ts_finalize_subtest
# the same, but requested by scols_table_set_json_format()
ts_init_subtest "api-$fmt"
ts_run "$TESTPROG" --batch 3 --json-format "$fmt" >> "$TS_OUTPUT" 2>> "$TS_ERRLOG"
ts_finalize_subtest
done
# the API overwrites the environment variable
ts_init_subtest "api-overwrites-env"
LIBSMARTCOLS_JSON="pretty" ts_run "$TESTPROG" --batch 2 --json-format "lines" \
>> "$TS_OUTPUT" 2>> "$TS_ERRLOG"
ts_finalize_subtest
ts_init_subtest "api-unsupported"
"$TESTPROG" --json-format "nonsense" >> "$TS_OUTPUT" 2>&1
echo "rc=$?" >> "$TS_OUTPUT"
ts_finalize_subtest
ts_finalize