aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmkhint41
-rwxr-xr-xtests/mkhint_test.sh92
2 files changed, 123 insertions, 10 deletions
diff --git a/mkhint b/mkhint
index 1629671..83f7840 100755
--- a/mkhint
+++ b/mkhint
@@ -93,6 +93,12 @@ Exit codes:
EOF
}
+# Pad a possibly-multibyte glyph (0 or 1 display column) to a fixed width.
+_pad_glyph() {
+ local g="$1" w="$2"
+ if [[ -n "$g" ]]; then printf "%s%*s" "$g" $((w - 1)) ""; else printf "%*s" "$w" ""; fi
+}
+
# List hint files
list_hint_files() {
if [[ ! -d "$HINT_DIR" ]]; then
@@ -101,18 +107,18 @@ list_hint_files() {
fi
# Color only on a TTY, or when forced for tests. tput optional.
- local c_on="" c_off=""
+ local c_on="" c_off="" g_on=""
if [[ -n "$MKHINT_FORCE_COLOR" || -t 1 ]]; then
if command -v tput &>/dev/null && tput setaf 3 &>/dev/null; then
- c_on=$(tput setaf 3); c_off=$(tput sgr0)
+ c_on=$(tput setaf 3); g_on=$(tput setaf 2); c_off=$(tput sgr0)
else
- c_on=$'\033[33m'; c_off=$'\033[0m'
+ c_on=$'\033[33m'; g_on=$'\033[32m'; c_off=$'\033[0m'
fi
fi
echo "Hint files in: $HINT_DIR"
echo "======================================================="
- printf "%-40s %22s %22s %-20s %s\n" "File" "HintVer" "SBOVer" "Category" "Created"
+ printf "%-40s %22s %22s %-20s %-6s %s\n" "File" "HintVer" "SBOVer" "Category" "DelReq" "Created"
echo "-------------------------------------------------------"
MATCHED_PKGS=()
@@ -122,6 +128,8 @@ list_hint_files() {
local VER; VER=$(grep "^VERSION" "$file" |cut -d '"' -f2)
# Skip hints with no VERSION set.
[[ -z "$VER" ]] && continue
+ local delreq=""
+ grep -q '^DELREQUIRES="..*"' "$file" && delreq="✓"
local name; name=$(basename "$file")
local pkg="${name%.hint}"
local info_file
@@ -133,14 +141,29 @@ list_hint_files() {
category=$(basename "$(dirname "$(dirname "$info_file")")")
fi
local date; date=$(stat -c "%y" "$file" | cut -d'.' -f1)
- local row
- row=$(printf "%-40s %22s %22s %-20s %s" "$name" "$VER" "$SBO_VER" "$category" "$date")
- if [[ -n "$VER" && "$VER" == "$SBO_VER" ]]; then
+ local dr; dr=$(_pad_glyph "$delreq" 6)
+ local hv sv
+ hv=$(printf "%22s" "$VER")
+ sv=$(printf "%22s" "$SBO_VER")
+ if [[ -n "$SBO_VER" && "$VER" == "$SBO_VER" ]]; then
+ # equal → whole row yellow
+ local row
+ row=$(printf "%-40s %s %s %-20s %s %s" "$name" "$hv" "$sv" "$category" "$dr" "$date")
printf "%s%s%s\n" "$c_on" "$row" "$c_off"
MATCHED_PKGS+=("$pkg")
matched=$((matched + 1))
else
- printf "%s\n" "$row"
+ # differ (or no SBO_VER) → green the newer cell, row plain
+ if [[ -n "$SBO_VER" ]]; then
+ local newer
+ newer=$(printf '%s\n%s\n' "$VER" "$SBO_VER" | sort -V | tail -1)
+ if [[ "$newer" == "$VER" ]]; then
+ hv="${g_on}${hv}${c_off}"
+ else
+ sv="${g_on}${sv}${c_off}"
+ fi
+ fi
+ printf "%-40s %s %s %-20s %s %s\n" "$name" "$hv" "$sv" "$category" "$dr" "$date"
fi
count=$((count + 1))
fi
@@ -153,7 +176,7 @@ list_hint_files() {
echo "======================================================="
echo "Total: $count file(s)"
if [[ $matched -gt 0 && -n "$c_on" ]]; then
- echo "(highlighted = hint version matches SBo .info)"
+ echo "(yellow row = versions match; green = newer side)"
fi
}
diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh
index 974441c..1877112 100755
--- a/tests/mkhint_test.sh
+++ b/tests/mkhint_test.sh
@@ -820,7 +820,7 @@ out=$(MKHINT_FORCE_COLOR=1 run_mkhint -l 2>&1)
echo "$out" | grep -q $'\033\[33m.*curl.hint' \
&& { echo " PASS: curl row highlighted"; (( PASS++ )); } \
|| { echo " FAIL: curl row not highlighted"; echo "$out" | cat -v | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T36 highlight"); }
-echo "$out" | grep -q "highlighted = hint version matches" \
+echo "$out" | grep -q "yellow row = versions match" \
&& { echo " PASS: legend shown"; (( PASS++ )); } \
|| { echo " FAIL: legend missing"; (( FAIL++ )); ERRORS+=("T36 legend"); }
# clion row must NOT carry the color start code
@@ -1147,6 +1147,96 @@ code=$?
set -e
assert_exit_code "missing hint" 2 "$code"
+# ── T60: -l hint newer than SBo → HintVer cell green ─────────────────────────
+echo ""
+echo "T60: -l hint version newer than .info → HintVer green"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+# curl .info is 8.5.0; hint 8.6.0 is newer
+cat > "$MOCK_HINT/curl.hint" << 'EOF'
+VERSION="8.6.0"
+ARCH="x86_64"
+DOWNLOAD="https://curl.se/download/curl-8.6.0.tar.gz"
+MD5SUM="abc123def456abc123def456abc123de"
+EOF
+out=$(MKHINT_FORCE_COLOR=1 run_mkhint -l 2>&1)
+# green start code (ESC[32m) appears before the hint version 8.6.0 on the curl row
+echo "$out" | grep curl.hint | grep -q $'\033\[32m.*8\.6\.0' \
+ && { echo " PASS: HintVer green when hint newer"; (( PASS++ )); } \
+ || { echo " FAIL: HintVer not green"; echo "$out" | grep curl.hint | cat -v | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T60 green"); }
+# whole row must NOT be yellow (differing versions)
+echo "$out" | grep curl.hint | grep -q $'\033\[33m' \
+ && { echo " FAIL: differing row wrongly yellow"; (( FAIL++ )); ERRORS+=("T60 yellow"); } \
+ || { echo " PASS: differing row not yellow"; (( PASS++ )); }
+
+# ── T61: -l SBo newer than hint → SBOVer cell green ──────────────────────────
+echo ""
+echo "T61: -l .info version newer than hint → SBOVer green"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+# curl .info is 8.5.0; hint 8.4.0 is older
+cat > "$MOCK_HINT/curl.hint" << 'EOF'
+VERSION="8.4.0"
+ARCH="x86_64"
+DOWNLOAD="https://curl.se/download/curl-8.4.0.tar.gz"
+MD5SUM="abc123def456abc123def456abc123de"
+EOF
+out=$(MKHINT_FORCE_COLOR=1 run_mkhint -l 2>&1)
+# green start code appears before the SBo version 8.5.0 on the curl row
+echo "$out" | grep curl.hint | grep -q $'\033\[32m.*8\.5\.0' \
+ && { echo " PASS: SBOVer green when .info newer"; (( PASS++ )); } \
+ || { echo " FAIL: SBOVer not green"; echo "$out" | grep curl.hint | cat -v | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T61 green"); }
+
+# ── T62: -l equal versions → whole row yellow, no green ──────────────────────
+echo ""
+echo "T62: -l equal versions → yellow row, no green cell"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+cat > "$MOCK_HINT/curl.hint" << 'EOF'
+VERSION="8.5.0"
+ARCH="x86_64"
+DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz"
+MD5SUM="abc123def456abc123def456abc123de"
+EOF
+out=$(MKHINT_FORCE_COLOR=1 run_mkhint -l 2>&1)
+echo "$out" | grep curl.hint | grep -q $'\033\[33m' \
+ && { echo " PASS: equal row yellow"; (( PASS++ )); } \
+ || { echo " FAIL: equal row not yellow"; echo "$out" | grep curl.hint | cat -v | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T62 yellow"); }
+echo "$out" | grep curl.hint | grep -q $'\033\[32m' \
+ && { echo " FAIL: equal row wrongly green"; (( FAIL++ )); ERRORS+=("T62 green"); } \
+ || { echo " PASS: equal row has no green"; (( PASS++ )); }
+
+# ── T63: -l shows ✓ in DelReq for hint with DELREQUIRES ──────────────────────
+echo ""
+echo "T63: -l DelReq column shows ✓ when DELREQUIRES populated"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+cat > "$MOCK_HINT/curl.hint" << 'EOF'
+VERSION="8.5.0"
+ARCH="x86_64"
+DELREQUIRES="rust-opt"
+DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz"
+MD5SUM="abc123def456abc123def456abc123de"
+EOF
+out=$(run_mkhint -l 2>&1)
+echo "$out" | grep -q "DelReq" \
+ && { echo " PASS: DelReq header present"; (( PASS++ )); } \
+ || { echo " FAIL: DelReq header missing"; echo "$out" | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T63 header"); }
+echo "$out" | grep curl.hint | grep -q "✓" \
+ && { echo " PASS: ✓ shown for DELREQUIRES hint"; (( PASS++ )); } \
+ || { echo " FAIL: ✓ missing"; echo "$out" | grep curl.hint | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T63 check"); }
+
+# ── T64: -l DelReq blank when no DELREQUIRES ─────────────────────────────────
+echo ""
+echo "T64: -l DelReq column blank when no DELREQUIRES"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+cat > "$MOCK_HINT/curl.hint" << 'EOF'
+VERSION="8.5.0"
+ARCH="x86_64"
+DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz"
+MD5SUM="abc123def456abc123def456abc123de"
+EOF
+out=$(run_mkhint -l 2>&1)
+echo "$out" | grep curl.hint | grep -q "✓" \
+ && { echo " FAIL: ✓ shown without DELREQUIRES"; (( FAIL++ )); ERRORS+=("T64 check"); } \
+ || { echo " PASS: no ✓ without DELREQUIRES"; (( PASS++ )); }
+
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
teardown