diff options
| -rw-r--r-- | lib/color-names.c | 6 | ||||
| -rw-r--r-- | tests/commands.sh | 1 | ||||
| -rw-r--r-- | tests/expected/misc/colors | 22 | ||||
| -rwxr-xr-x | tests/ts/misc/colors | 42 |
4 files changed, 68 insertions, 3 deletions
diff --git a/lib/color-names.c b/lib/color-names.c index f7b1946090..88c4ef9577 100644 --- a/lib/color-names.c +++ b/lib/color-names.c @@ -43,7 +43,7 @@ const char *color_sequence_from_colorname(const char *str) { "halfbright", UL_COLOR_HALFBRIGHT }, { "lightblue", UL_COLOR_BOLD_BLUE }, { "lightcyan", UL_COLOR_BOLD_CYAN }, - { "lightgray,", UL_COLOR_GRAY }, + { "lightgray", UL_COLOR_GRAY }, { "lightgreen", UL_COLOR_BOLD_GREEN }, { "lightmagenta", UL_COLOR_BOLD_MAGENTA }, { "lightred", UL_COLOR_BOLD_RED }, @@ -51,8 +51,8 @@ const char *color_sequence_from_colorname(const char *str) { "red", UL_COLOR_RED }, { "reset", UL_COLOR_RESET, }, { "reverse", UL_COLOR_REVERSE }, - { "yellow", UL_COLOR_BOLD_YELLOW }, - { "white", UL_COLOR_WHITE } + { "white", UL_COLOR_WHITE }, + { "yellow", UL_COLOR_BOLD_YELLOW } }; struct ul_color_name key = { .name = str }, *res; diff --git a/tests/commands.sh b/tests/commands.sh index b79d7c650a..fe989a541a 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 0000000000..c6ae7ce93a --- /dev/null +++ b/tests/expected/misc/colors @@ -0,0 +1,22 @@ + black: [30mHello World![0m + blink: [5mHello World![0m + blue: [34mHello World![0m + bold: [1mHello World![0m + brown: [33mHello World![0m + cyan: [36mHello World![0m + darkgray: [1;30mHello World![0m + gray: [37mHello World![0m + green: [32mHello World![0m + halfbright: [2mHello World![0m + lightblue: [1;34mHello World![0m + lightcyan: [1;36mHello World![0m + lightgray: [37mHello World![0m + lightgreen: [1;32mHello World![0m + lightmagenta: [1;35mHello World![0m + lightred: [1;31mHello World![0m + magenta: [35mHello World![0m + red: [31mHello World![0m + reset: [0mHello World![0m + reverse: [7mHello World![0m + white: [1;37mHello World![0m + yellow: [1;33mHello World![0m diff --git a/tests/ts/misc/colors b/tests/ts/misc/colors new file mode 100755 index 0000000000..bae7599ace --- /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 <kzak@redhat.com> +# +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 + |
