#!/bin/sh
# Build and run a tiny downstream program against the packaged seq_io crate.
# This is deliberately limited: the upstream integration tests need development
# dependencies that are not packaged in Debian.
set -eu

# Overridable only to run this test outside a Debian testbed.
registry="${SEQ_IO_DEBIAN_REGISTRY:-/usr/share/cargo/registry}"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT HUP INT TERM

mkdir -p "$tmp/src" "$tmp/.cargo"
cp "$(dirname "$0")/smoke.rs" "$tmp/src/main.rs"

cat > "$tmp/Cargo.toml" <<'EOF'
[package]
name = "seq-io-autopkgtest"
version = "0.0.0"
edition = "2021"

[dependencies]
seq_io = "0.3"
EOF

cat > "$tmp/.cargo/config.toml" <<EOF
[source.crates-io]
replace-with = "debian"

[source.debian]
directory = "$registry"
EOF

cd "$tmp"
CARGO_HOME="$tmp/cargo-home" CARGO_NET_OFFLINE=true \
    cargo run --offline --quiet
