aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmkhint13
-rwxr-xr-xtests/mkhint_test.sh25
2 files changed, 38 insertions, 0 deletions
diff --git a/mkhint b/mkhint
index 20b20a8..e8c4fab 100755
--- a/mkhint
+++ b/mkhint
@@ -817,6 +817,19 @@ _has_nvchecker_section() {
"$NVCHECKER_CONFIG"
}
+# Print the [pkg] section (header + body) from NVCHECKER_CONFIG: from the label
+# line until the next line starting with '[' or EOF. Empty if not found.
+_extract_nvchecker_section() {
+ local pkg="$1"
+ [[ -f "$NVCHECKER_CONFIG" ]] || return 0
+ local label; label=$(_nvchecker_label "$pkg")
+ awk -v lbl="$label" '
+ $0==lbl { grab=1; print; next }
+ grab && /^\[/ { exit }
+ grab { print }
+ ' "$NVCHECKER_CONFIG"
+}
+
# Extract a package name from a language-registry download URL.
# Args: <url> <prgnam-fallback>. Prints the parsed name, or the fallback
# (PRGNAM) when no host-specific pattern matches.
diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh
index 075f542..7af0e7f 100755
--- a/tests/mkhint_test.sh
+++ b/tests/mkhint_test.sh
@@ -2015,6 +2015,31 @@ assert_contains "cran field" "$d_out" 'cran = "foo"'
unk=$(awk '/^### unknown/{f=1;next} /^### end/{f=0} f' "$d_out")
assert_exit_code "unknown host empty body" 0 "$( [[ -z "${unk//[[:space:]]/}" ]]; echo $? )"
+# ── T-NV3: _extract_nvchecker_section prints one section ──────────────────────
+echo ""
+echo "T-NV3: _extract_nvchecker_section returns the [pkg] block only"
+NVCHECKER_CONFIG="$MOCK_BASE/nv_extract.toml"
+cat > "$NVCHECKER_CONFIG" << 'EOF'
+[alpha]
+source = "github"
+github = "a/alpha"
+
+[beta]
+source = "pypi"
+pypi = "beta"
+
+[gamma]
+source = "cran"
+cran = "gamma"
+EOF
+ex_out="$MOCK_BASE/nv_extract.txt"
+_extract_nvchecker_section beta > "$ex_out"
+assert_contains "beta header" "$ex_out" '^\[beta\]$'
+assert_contains "beta field" "$ex_out" 'pypi = "beta"'
+assert_not_contains "no alpha" "$ex_out" 'alpha'
+assert_not_contains "no gamma" "$ex_out" 'gamma'
+NVCHECKER_CONFIG="$MOCK_BASE/nvchecker.toml"
+
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
teardown