diff options
| -rwxr-xr-x | mkhint | 42 | ||||
| -rwxr-xr-x | tests/mkhint_test.sh | 78 |
2 files changed, 91 insertions, 29 deletions
@@ -933,9 +933,12 @@ add_nvchecker_section() { local label; label=$(_nvchecker_label "$pkg") - # Skip if section already present + # Already present: dump the existing section so the user sees what's set. if _has_nvchecker_section "$pkg"; then - echo "nvchecker: ${label} already present in $NVCHECKER_CONFIG" + echo "nvchecker: ${label} already present in $NVCHECKER_CONFIG:" + echo "────────────────────────────" + _extract_nvchecker_section "$pkg" + echo "────────────────────────────" return 0 fi @@ -946,27 +949,10 @@ add_nvchecker_section() { fi local haystack="${download} ${homepage}" - local section="" - if [[ "$haystack" =~ github\.com/([A-Za-z0-9._-]+)/([A-Za-z0-9._-]+) ]]; then - local owner="${BASH_REMATCH[1]}" - local repo="${BASH_REMATCH[2]}" - repo="${repo%.git}" - section=$(cat <<EOF - -${label} -source = "github" -github = "${owner}/${repo}" -use_max_tag = true -EOF -) - elif [[ "$haystack" =~ (pypi\.org|files\.pythonhosted\.org) ]]; then - section=$(cat <<EOF - -${label} -source = "pypi" -pypi = "${pkg}" -EOF -) + local body; body=$(_detect_nvchecker_source "$haystack" "$pkg") + local section + if [[ -n "$body" ]]; then + section=$(printf '\n%s\n%s' "$label" "$body") else section=$(cat <<EOF @@ -981,7 +967,15 @@ EOF fi printf '%s\n' "$section" >> "$NVCHECKER_CONFIG" - echo "nvchecker: review/fill ${label} section in $NVCHECKER_CONFIG" + echo "nvchecker: added ${label} section to $NVCHECKER_CONFIG:" + echo "────────────────────────────" + printf '%s\n' "$label" + if [[ -n "$body" ]]; then + printf '%s' "$body" + else + echo "# TODO: configure nvchecker source for \"${pkg}\"" + fi + echo "────────────────────────────" } # Add NODOWNLOAD=yes after MD5SUM_x86_64 line if not already present diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh index 7af0e7f..271e68e 100755 --- a/tests/mkhint_test.sh +++ b/tests/mkhint_test.sh @@ -18,6 +18,9 @@ setup() { "$MOCK_REPO/development/clion" \ "$MOCK_REPO/development/ghpkg" \ "$MOCK_REPO/python/pypkg" \ + "$MOCK_REPO/development/glpkg" \ + "$MOCK_REPO/development/cbpkg" \ + "$MOCK_REPO/development/crpkg" \ "$MOCK_REPO/multimedia/yt-dlp" \ "$MOCK_REPO/development/gopkg" \ "$MOCK_REPO/development/rustpkg" \ @@ -112,6 +115,43 @@ MAINTAINER="Test" EMAIL="test@test.com" EOF + cat > "$MOCK_REPO/development/glpkg/glpkg.info" << 'EOF' +PRGNAM="glpkg" +VERSION="1.0.0" +HOMEPAGE="https://gitlab.com/someowner/glpkg" +DOWNLOAD="https://gitlab.com/someowner/glpkg/-/archive/1.0.0/glpkg-1.0.0.tar.gz" +MD5SUM="abc123def456abc123def456abc123de" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +REQUIRES="" +MAINTAINER="Test" +EMAIL="test@test.com" +EOF + cat > "$MOCK_REPO/development/cbpkg/cbpkg.info" << 'EOF' +PRGNAM="cbpkg" +VERSION="1.0.0" +HOMEPAGE="https://codeberg.org/someowner/cbpkg" +DOWNLOAD="https://codeberg.org/someowner/cbpkg/archive/1.0.0.tar.gz" +MD5SUM="abc123def456abc123def456abc123de" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +REQUIRES="" +MAINTAINER="Test" +EMAIL="test@test.com" +EOF + cat > "$MOCK_REPO/development/crpkg/crpkg.info" << 'EOF' +PRGNAM="crpkg" +VERSION="1.0.0" +HOMEPAGE="https://cran.r-project.org/package=crpkg" +DOWNLOAD="https://cran.r-project.org/src/contrib/crpkg_1.0.0.tar.gz" +MD5SUM="abc123def456abc123def456abc123de" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +REQUIRES="" +MAINTAINER="Test" +EMAIL="test@test.com" +EOF + # github .info with a dash in the package name (needs TOML quoting) cat > "$MOCK_REPO/multimedia/yt-dlp/yt-dlp.info" << 'EOF' PRGNAM="yt-dlp" @@ -534,10 +574,13 @@ assert_file_not_exists "b.bak removed" "$MOCK_HINT/b.hint.bak" # ── T16: --new github .info → github source section ─────────────────────────── echo "" echo "T16: --new github .info → [pkg] source=github appended" -run_mkhint -n ghpkg +run_mkhint -n ghpkg > "$MOCK_BASE/t16.out" 2>&1 assert_contains "github section header" "$MOCK_BASE/nvchecker.toml" '\[ghpkg\]' assert_contains "github source" "$MOCK_BASE/nvchecker.toml" 'source = "github"' assert_contains "github owner/repo" "$MOCK_BASE/nvchecker.toml" 'github = "someowner/ghpkg"' +assert_contains "github latest_release" "$MOCK_BASE/nvchecker.toml" 'use_latest_release = true' +assert_contains "github max_tag comment" "$MOCK_BASE/nvchecker.toml" '# use_max_tag = true' +assert_contains "T16 stanza echoed" "$MOCK_BASE/t16.out" 'source = "github"' # ── T17: --new pypi .info → pypi source section ─────────────────────────────── echo "" @@ -550,16 +593,41 @@ assert_contains "pypi name" "$MOCK_BASE/nvchecker.toml" 'pypi = "p # ── T18: --new unrecognised URL → commented stub ────────────────────────────── echo "" echo "T18: --new unknown source → commented stub appended" -run_mkhint -n clion +rm -f "$MOCK_HINT/clion.hint" "$MOCK_HINT/clion.hint.bak" # force fresh --new (T8 already created one) +run_mkhint -n clion > "$MOCK_BASE/t18.out" 2>&1 assert_contains "clion section header" "$MOCK_BASE/nvchecker.toml" '\[clion\]' assert_contains "stub TODO" "$MOCK_BASE/nvchecker.toml" 'TODO: configure nvchecker source' +assert_contains "T18 stub echoed" "$MOCK_BASE/t18.out" 'TODO: configure nvchecker source' -# ── T19: --new when [pkg] already present → no duplicate ─────────────────────── +# ── T19: --new when [pkg] already present → no duplicate, dumps existing ─────── echo "" -echo "T19: --new when section exists → not duplicated" -run_mkhint -n ghpkg # ghpkg section already added in T16 +echo "T19: --new when section exists → not duplicated, existing dumped" +rm -f "$MOCK_HINT/ghpkg.hint" "$MOCK_HINT/ghpkg.hint.bak" # force fresh --new; nvchecker section stays from T16 +run_mkhint -n ghpkg > "$MOCK_BASE/t19.out" 2>&1 # ghpkg section already added in T16 dup_count=$(grep -c '^\[ghpkg\]' "$MOCK_BASE/nvchecker.toml") assert_exit_code "ghpkg section appears once" 1 "$dup_count" +assert_contains "T19 dumps existing" "$MOCK_BASE/t19.out" 'github = "someowner/ghpkg"' + +# ── T-NV4: --new gitlab .info → gitlab section ──────────────────────────────── +echo "" +echo "T-NV4: --new gitlab .info → source=gitlab" +run_mkhint -n glpkg > /dev/null 2>&1 +assert_contains "gitlab source" "$MOCK_BASE/nvchecker.toml" 'source = "gitlab"' +assert_contains "gitlab field" "$MOCK_BASE/nvchecker.toml" 'gitlab = "someowner/glpkg"' + +# ── T-NV5: --new codeberg .info → gitea source + host ───────────────────────── +echo "" +echo "T-NV5: --new codeberg .info → gitea + host" +run_mkhint -n cbpkg > /dev/null 2>&1 +assert_contains "codeberg source" "$MOCK_BASE/nvchecker.toml" 'source = "gitea"' +assert_contains "codeberg host" "$MOCK_BASE/nvchecker.toml" 'host = "codeberg.org"' + +# ── T-NV6: --new cran .info → cran source ───────────────────────────────────── +echo "" +echo "T-NV6: --new cran .info → source=cran" +run_mkhint -n crpkg > /dev/null 2>&1 +assert_contains "cran source" "$MOCK_BASE/nvchecker.toml" 'source = "cran"' +assert_contains "cran field" "$MOCK_BASE/nvchecker.toml" 'cran = "crpkg"' # ── T20: --hintfile no -v, accept suggestion → VERSION=latest, nvtake called ─── echo "" |
