Luigit
repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by admin

xtask/tests/fixtures/cargo-offline.sh

Raw
#!/bin/sh
set -eu

fail() {
    printf '%s\n' "offline Cargo fixture: $*" >&2
    exit 2
}

if [ "$#" -eq 4 ] && [ "$1" = metadata ] && [ "$2" = --locked ] && [ "$3" = --format-version=1 ] && [ "$4" = --offline ]; then
    cat "$SMITH_METADATA"
    exit
fi

if [ "$#" -ne 3 ] || [ "$1" != metadata ] || [ "$2" != --format-version=1 ] || [ "$3" != --offline ]; then
    fail 'unexpected invocation'
fi

line=$(awk '/^probe = / { if (found) exit 2; found = $0 } END { if (!found) exit 1; print found }' Cargo.toml) || fail 'probe declaration missing or duplicated'
case "$line" in
    'probe = { package = "ureq", version = "~3.4", default-features = false }')
        package=ureq
        requirement=~3.4
        ;;
    'probe = { package = "ureq", version = "*", default-features = false }')
        package=ureq
        requirement='*'
        ;;
    'probe = { package = "wasmtime", version = "^49.0.2", default-features = false }')
        package=wasmtime
        requirement='^49.0.2'
        ;;
    'probe = { package = "wasmtime", version = "*", default-features = false }')
        package=wasmtime
        requirement='*'
        ;;
    'probe = { package = "wit-bindgen", version = "=0.62.0", default-features = false }')
        package=wit-bindgen
        requirement='=0.62.0'
        ;;
    'probe = { package = "wit-bindgen", version = "*", default-features = false }')
        package=wit-bindgen
        requirement='*'
        ;;
    *) fail 'unknown probe package or requirement';;
esac

case "$package:$requirement" in
    ureq:~3.4) fixture=ureq-compatible.json ;;
    ureq:*) fixture=ureq-latest.json ;;
    wasmtime:^49.0.2) fixture=wasmtime-compatible.json ;;
    wasmtime:*) fixture=wasmtime-latest.json ;;
    wit-bindgen:=0.62.0) fixture=wit-bindgen-compatible.json ;;
    wit-bindgen:*) fixture=wit-bindgen-latest.json ;;
    *) fail 'unknown probe package or requirement';;
esac
cat "$SMITH_FIXTURES/$fixture"