From: Karel Zak Date: Mon, 25 Aug 2025 11:07:21 +0000 (+0200) Subject: tests: add color names test X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=36a3c19e9a10afe83c9f3e6570521ad4ad252ef2;p=thirdparty%2Futil-linux.git tests: add color names test Signed-off-by: Karel Zak --- diff --git a/tests/commands.sh b/tests/commands.sh index b79d7c650..fe989a541 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -4,6 +4,7 @@ TS_TESTUSER=${TS_TESTUSER:-"nobody"} # helpers TS_HELPER_BOILERPLATE="${ts_helpersdir}test_boilerplate" TS_HELPER_BYTESWAP="${ts_helpersdir}test_byteswap" +TS_HELPER_COLORS="${ts_helpersdir}test_colors" TS_HELPER_CPUSET="${ts_helpersdir}test_cpuset" TS_HELPER_CAP="${ts_helpersdir}test_cap" TS_HELPER_DMESG="${ts_helpersdir}test_dmesg" diff --git a/tests/expected/misc/colors b/tests/expected/misc/colors new file mode 100644 index 000000000..c6ae7ce93 --- /dev/null +++ b/tests/expected/misc/colors @@ -0,0 +1,22 @@ + black: Hello World! + blink: Hello World! + blue: Hello World! + bold: Hello World! + brown: Hello World! + cyan: Hello World! + darkgray: Hello World! + gray: Hello World! + green: Hello World! + halfbright: Hello World! + lightblue: Hello World! + lightcyan: Hello World! + lightgray: Hello World! + lightgreen: Hello World! + lightmagenta: Hello World! + lightred: Hello World! + magenta: Hello World! + red: Hello World! + reset: Hello World! + reverse: Hello World! + white: Hello World! + yellow: Hello World! diff --git a/tests/ts/misc/colors b/tests/ts/misc/colors new file mode 100755 index 000000000..bae7599ac --- /dev/null +++ b/tests/ts/misc/colors @@ -0,0 +1,42 @@ +#!/bin/bash + +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# This program 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. +# +# Copyright (C) 2025 Karel Zak +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="colors" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_HELPER_COLORS" +ts_cd "$TS_OUTDIR" + +SRC="${top_srcdir}/lib/color-names.c" + +COLOR_NAMES=$(awk ' + /basic_schemes\[\]/ { in_array=1; next } + in_array && /};/ { exit } + in_array && /\{[[:space:]]*"/ { + sub(/.*\{[[:space:]]*"/, "") + if (match($0, /[^"]*/)) { + name = substr($0, RSTART, RLENGTH) + print name + } + } +' "$SRC") + +for color in $COLOR_NAMES; do + printf "%15s: " "$color" >> $TS_OUTPUT + $TS_HELPER_COLORS --mode always --color "$color" >> $TS_OUTPUT 2>> $TS_ERRLOG +done + +ts_finalize +