]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add color names test
authorKarel Zak <kzak@redhat.com>
Mon, 25 Aug 2025 11:07:21 +0000 (13:07 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 25 Aug 2025 12:50:24 +0000 (14:50 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
tests/commands.sh
tests/expected/misc/colors [new file with mode: 0644]
tests/ts/misc/colors [new file with mode: 0755]

index b79d7c650a8b9717aae821973e0d0ee55cf5004c..fe989a541aa4915334b8680d1aeafc35bcccd11b 100644 (file)
@@ -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 (file)
index 0000000..c6ae7ce
--- /dev/null
@@ -0,0 +1,22 @@
+          black: \e[30mHello World!\e[0m
+          blink: \e[5mHello World!\e[0m
+           blue: \e[34mHello World!\e[0m
+           bold: \e[1mHello World!\e[0m
+          brown: \e[33mHello World!\e[0m
+           cyan: \e[36mHello World!\e[0m
+       darkgray: \e[1;30mHello World!\e[0m
+           gray: \e[37mHello World!\e[0m
+          green: \e[32mHello World!\e[0m
+     halfbright: \e[2mHello World!\e[0m
+      lightblue: \e[1;34mHello World!\e[0m
+      lightcyan: \e[1;36mHello World!\e[0m
+      lightgray: \e[37mHello World!\e[0m
+     lightgreen: \e[1;32mHello World!\e[0m
+   lightmagenta: \e[1;35mHello World!\e[0m
+       lightred: \e[1;31mHello World!\e[0m
+        magenta: \e[35mHello World!\e[0m
+            red: \e[31mHello World!\e[0m
+          reset: \e[0mHello World!\e[0m
+        reverse: \e[7mHello World!\e[0m
+          white: \e[1;37mHello World!\e[0m
+         yellow: \e[1;33mHello World!\e[0m
diff --git a/tests/ts/misc/colors b/tests/ts/misc/colors
new file mode 100755 (executable)
index 0000000..bae7599
--- /dev/null
@@ -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
+