#!/usr/bin/env bash # Table-driven cases for depcheck.sh range rules, run against a scratch tree. set -eu here="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" tmp="$(mktemp -d)" trap 'rm -r "${tmp:?}"' EXIT mkdir "$tmp/scripts" "$tmp/a" "$tmp/b" cp "$here/depcheck.sh" "$tmp/scripts/" printf 'name = "atproto_x"\n[dependencies]\n' >"$tmp/b/gleam.toml" cases=( "pass|>= 0.2.0 and < 0.3.0" "pass|>= 0.1.1 and < 0.3.0" "pass|>= 0.1.1 and < 0.2.0 or >= 0.2.0 and < 0.3.0" "pass|>= 1.2.0 and < 2.0.0" "pass|>= 1.2.0 and < 1.5.0" "fail|>= 0.2.0 and < 1.0.0" "fail|>= 0.2.0" "fail|>= 0.2.1 and < 0.2.5" "fail|>= 0.2.0 and < 0.3.1" "fail|>= 0.2.0 and < 0.2.0" "fail|>= 0.2.0 and < 0.1.0" "fail|>= 1.2.0 and < 3.0.0" "fail|>= 1.2.0 and < 1.2.0" "fail|~> 0.2" ) bad=0 for c in "${cases[@]}"; do want="${c%%|*}" req="${c#*|}" printf 'name = "a"\n[dependencies]\natproto_x = "%s"\n' "$req" >"$tmp/a/gleam.toml" bash "$tmp/scripts/depcheck.sh" >/dev/null 2>&1 && got=pass || got=fail [[ "$got" == "$want" ]] || { echo "depcheck_test: '$req' wanted $want, got $got" >&2; bad=1; } done printf 'name = "a"\n[dependencies]\natproto_x = { path = "../b" }\n' >"$tmp/a/gleam.toml" bash "$tmp/scripts/depcheck.sh" >/dev/null 2>&1 && { echo "depcheck_test: path dep passed" >&2; bad=1; } ((bad == 0)) && echo "depcheck_test: ok (${#cases[@]} range cases + path dep)" exit "$bad"