#!/usr/bin/env bats # # The xara entry in compile.conf, built from a fake upstream with cargo stubbed load helpers setup() { setup_fake_home # A fake xara repo with the files the build steps use, tagged like upstream UPSTREAM="$BATS_TEST_TMPDIR/xara" mkdir -p "$UPSTREAM"/dist/{man,systemd,udev} touch "$UPSTREAM"/dist/man/xara.1 "$UPSTREAM"/dist/man/xara-monitor.1 printf '[Service]\nExecStart=/usr/bin/xara --config %%E/xara/xara.conf\n' > "$UPSTREAM/dist/systemd/xara.service" echo '# udev' > "$UPSTREAM/dist/udev/60-xara-ptt.rules" echo '#call = YOURCALL' > "$UPSTREAM/dist/xara.conf.example" git -C "$UPSTREAM" init -q git -C "$UPSTREAM" add -A git -C "$UPSTREAM" -c user.email=t@t -c user.name=t commit -q -m init git -C "$UPSTREAM" tag v0.1.3 # The real compile.conf entry, pointed at the fake repo export HAMPACK_COMPILE_CONF="$BATS_TEST_TMPDIR/compile.conf" sed -n '/^\[xara\]/,/^$/p' "$REPO/compile.conf" \ | sed "s|^git=.*|git=file://$UPSTREAM|" > "$HAMPACK_COMPILE_CONF" stub cargo 'mkdir -p target/release && echo xara > target/release/xara && echo monitor > target/release/xara-monitor' } @test "xara is built without the registered feature" { ! sed -n '/^\[xara\]/,/^$/p' "$REPO/compile.conf" | grep '^steps=' | grep -q registered } @test "first install builds xara and installs it, its service and its config" { run bash "$REPO/install-compiled.sh" [ "$status" -eq 0 ] grep -qx "cargo build --release --locked -p xara" "$STUB_LOG" [ -x "$HOME/.local/bin/xara" ] [ -x "$HOME/.local/bin/xara-monitor" ] [ -f "$HOME/.local/share/man/man1/xara.1" ] grep -qx "ExecStart=$HOME/.local/bin/xara --config %E/xara/xara.conf" "$HOME/.config/systemd/user/xara.service" grep -q "^sudo cp -P --remove-destination .*/etc/udev/rules.d/60-xara-ptt.rules /etc/udev/rules.d/60-xara-ptt.rules$" "$STUB_LOG" [ "$(cat "$HOME/.config/xara/xara.conf")" = "#call = YOURCALL" ] grep -qx "$HOME/.local/bin/xara" "$HAMPACK_STATE/manifests/xara" grep -qx "/etc/udev/rules.d/60-xara-ptt.rules" "$HAMPACK_STATE/manifests/xara" grep -qx "xara=0.1.3" "$HAMPACK_STATE/.installed_versions" # The service is installed but not enabled: it needs a callsign first ! grep -q "systemctl --user enable" "$STUB_LOG" } @test "a rebuild keeps the user's xara.conf" { bash "$REPO/install-compiled.sh" echo "call = N0CALL" > "$HOME/.config/xara/xara.conf" sed -i 's/^version=.*/version=0.1.4/' "$HAMPACK_COMPILE_CONF" git -C "$UPSTREAM" tag v0.1.4 run bash "$REPO/install-compiled.sh" [ "$status" -eq 0 ] grep -qx "xara=0.1.4" "$HAMPACK_STATE/.installed_versions" [ "$(cat "$HOME/.config/xara/xara.conf")" = "call = N0CALL" ] } @test "a later update with xara current doesn't rebuild it" { bash "$REPO/install-compiled.sh" : > "$STUB_LOG" run bash "$REPO/install-compiled.sh" [ "$status" -eq 0 ] [[ "$output" == *"xara 0.1.3 is up to date"* ]] ! grep -q "^cargo " "$STUB_LOG" }