cram/integration_test.sh

117 lines
3.7 KiB
Bash
Executable file

#!/usr/bin/env bash
set -ex
dest=$(mktemp -d)
PATH="$PATH:$(realpath .)"
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
cram --help
root="test/integration"
function ,scrub() {
rm -rf "${dest}"/* .cram.log
}
# Should be able to list all packages
cram list "${root}" | grep "packages.d/p1"
,scrub
# P3 depends on P1, should show up in the listing
cram list "${root}" packages.d/p3 | grep "packages.d/p1"
,scrub
# P4 depends on P3, should show up in the listing
cram list "${root}" packages.d/p4 | grep "packages.d/p3"
,scrub
# The default profile should depend on its subpackage
cram list "${root}" profiles.d/default | grep "profiles.d/default/subpackage"
,scrub
# And the subpackage has a dep
cram list "${root}" profiles.d/default/subpackage | grep "packages.d/p3"
,scrub
# Install one package
cram apply --no-optimize --require packages.d/p1 --execute "${root}" "${dest}"
[ -L "${dest}"/foo ]
cram state "$root" | grep "${dest}/foo"
,scrub
# Install two transitively (legacy)
cram apply --no-optimize --require packages.d/p3 --execute "${root}" "${dest}"
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
cram state "$root" | grep "${dest}/foo"
cram state "$root" | grep "${dest}/bar"
,scrub
# Install two transitively (current)
cram apply --no-optimize --require packages.d/p4 --execute "${root}" "${dest}"
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
,scrub
# Install two transitively (current)
cram apply --no-optimize --require packages.d/p4 --execute "${root}" "${dest}"
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
,scrub
# Install two transitively (current)
cram apply --no-optimize --require hosts.d/test --require profiles.d/default --execute "${root}" "${dest}"
tree "${dest}"
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
,scrub
# INSTALL scripts get run as-is
cram list "${root}" packages.d/p5 | grep "packages.d/p5/INSTALL"
,scrub
# Inline scripts get pulled out repeatably
cram list "${root}" packages.d/p6 | grep "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b"
,scrub
# Inline scripts get pulled out repeatably, even from the list format
cram list "${root}" packages.d/p7 | grep "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b"
,scrub
# Test log-based optimization
cram apply --no-optimize --require packages.d/p4 --execute "${root}" "${dest}"
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
# These paths were already linked, they shouldn't be re-linked when optimizing.
! cram apply --require packages.d/p4 --optimize --execute "${root}" "${dest}" | grep "${dest}/foo"
! cram apply --require packages.d/p4 --optimize --execute "${root}" "${dest}" | grep "${dest}/bar"
,scrub
# Likewise, if we've exec'd this once we shouldn't do it again
cram apply --no-optimize --require packages.d/p5 --execute "${root}" "${dest}"
! cram apply --require packages.d/p5 --execute "${root}" "${dest}" | grep "exec"
,scrub
# ... unless the user tells us to
cram apply --no-optimize --require packages.d/p5 --execute "${root}" "${dest}"
cram apply --exec-always --require packages.d/p5 --execute "${root}" "${dest}" | grep "exec"
,scrub
# If multiple packages provide the same _effective_ script, do it once
cram apply --require packages.d/p6 --require packages.d/p7 --execute "${root}" "${dest}" | sort | uniq -c | grep "/tmp/stow/b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b.sh" | grep "1 - exec"
,scrub
# Test log-based cleanup
cram apply --require packages.d/p1 --require packages.d/p2 --execute "${root}" "${dest}"
cram apply --require packages.d/p1 --require packages.d/p2 --execute "${root}" "${dest}"
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
# And how bar shouldn't be installed...
cram apply --require packages.d/p1 --execute "${root}" "${dest}"
cram state "${root}"
[ -L "${dest}"/foo ]
[ ! -L "${dest}"/bar ]
,scrub