test: Expanded behaviour suite
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: "${HOMESICK_CMD:=/workspace/dist/gosick}"
|
: "${HOMESICK_CMD:=ruby /workspace/bin/homesick}"
|
||||||
: "${BEHAVIOR_VERBOSE:=0}"
|
: "${BEHAVIOR_VERBOSE:=0}"
|
||||||
|
|
||||||
RUN_OUTPUT=""
|
RUN_OUTPUT=""
|
||||||
@@ -80,6 +80,52 @@ run_homesick() {
|
|||||||
rm -f "$out_file"
|
rm -f "$out_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_homesick_with_stdin() {
|
||||||
|
local stdin_data="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
local out_file
|
||||||
|
local output
|
||||||
|
out_file="$(mktemp)"
|
||||||
|
if ! printf '%b' "$stdin_data" | bash -lc "$HOMESICK_CMD $*" >"$out_file" 2>&1; then
|
||||||
|
cat "$out_file" >&2
|
||||||
|
rm -f "$out_file"
|
||||||
|
fail "homesick command failed: $*"
|
||||||
|
fi
|
||||||
|
|
||||||
|
output="$(cat "$out_file")"
|
||||||
|
RUN_OUTPUT="$output"
|
||||||
|
|
||||||
|
if [[ "$BEHAVIOR_VERBOSE" == "1" && -n "$output" ]]; then
|
||||||
|
printf '%s\n' "$output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$out_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_homesick_with_env() {
|
||||||
|
local env_prefix="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
local out_file
|
||||||
|
local output
|
||||||
|
out_file="$(mktemp)"
|
||||||
|
if ! bash -lc "$env_prefix $HOMESICK_CMD $*" >"$out_file" 2>&1; then
|
||||||
|
cat "$out_file" >&2
|
||||||
|
rm -f "$out_file"
|
||||||
|
fail "homesick command failed: $*"
|
||||||
|
fi
|
||||||
|
|
||||||
|
output="$(cat "$out_file")"
|
||||||
|
RUN_OUTPUT="$output"
|
||||||
|
|
||||||
|
if [[ "$BEHAVIOR_VERBOSE" == "1" && -n "$output" ]]; then
|
||||||
|
printf '%s\n' "$output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$out_file"
|
||||||
|
}
|
||||||
|
|
||||||
setup_remote_castle() {
|
setup_remote_castle() {
|
||||||
local remote_dir="$1"
|
local remote_dir="$1"
|
||||||
local work_dir="$2"
|
local work_dir="$2"
|
||||||
@@ -125,13 +171,26 @@ run_suite() {
|
|||||||
|
|
||||||
setup_remote_castle "$remote_root" "$work_root"
|
setup_remote_castle "$remote_root" "$work_root"
|
||||||
|
|
||||||
echo "[1/7] clone"
|
echo "[1/18] help"
|
||||||
run_homesick "clone file://$remote_root/base.git parity-castle"
|
run_homesick "help"
|
||||||
assert_path_exists "$HOME/.homesick/repos/parity-castle/.git"
|
[[ "$RUN_OUTPUT" == *"Usage:"* || "$RUN_OUTPUT" == *"Commands:"* ]] || fail "expected help output to include command usage information"
|
||||||
assert_path_exists "$HOME/.homesick/repos/parity-castle/home/.vimrc"
|
run_homesick "help clone"
|
||||||
|
[[ "$RUN_OUTPUT" == *"clone"* ]] || fail "expected command help output for clone"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
echo "[2/7] link"
|
echo "[2/18] clone"
|
||||||
|
run_homesick "clone file://$remote_root/base.git parity-castle"
|
||||||
|
run_homesick "clone file://$remote_root/base.git parity-castle-2"
|
||||||
|
assert_path_exists "$HOME/.homesick/repos/parity-castle/.git"
|
||||||
|
assert_path_exists "$HOME/.homesick/repos/parity-castle/home/.vimrc"
|
||||||
|
assert_path_exists "$HOME/.homesick/repos/parity-castle-2/.git"
|
||||||
|
run_git -C "$HOME/.homesick/repos/parity-castle" config user.email "behavior@test.local"
|
||||||
|
run_git -C "$HOME/.homesick/repos/parity-castle" config user.name "Behavior Test"
|
||||||
|
run_git -C "$HOME/.homesick/repos/parity-castle-2" config user.email "behavior@test.local"
|
||||||
|
run_git -C "$HOME/.homesick/repos/parity-castle-2" config user.name "Behavior Test"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[3/18] link"
|
||||||
run_homesick "link parity-castle"
|
run_homesick "link parity-castle"
|
||||||
assert_symlink_target "$HOME/.vimrc" "$HOME/.homesick/repos/parity-castle/home/.vimrc"
|
assert_symlink_target "$HOME/.vimrc" "$HOME/.homesick/repos/parity-castle/home/.vimrc"
|
||||||
assert_symlink_target "$HOME/.zshrc" "$HOME/.homesick/repos/parity-castle/home/.zshrc"
|
assert_symlink_target "$HOME/.zshrc" "$HOME/.homesick/repos/parity-castle/home/.zshrc"
|
||||||
@@ -139,7 +198,7 @@ run_suite() {
|
|||||||
assert_symlink_target "$HOME/.config/myapp" "$HOME/.homesick/repos/parity-castle/home/.config/myapp"
|
assert_symlink_target "$HOME/.config/myapp" "$HOME/.homesick/repos/parity-castle/home/.config/myapp"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
echo "[3/7] unlink"
|
echo "[4/18] unlink"
|
||||||
run_homesick "unlink parity-castle"
|
run_homesick "unlink parity-castle"
|
||||||
assert_path_missing "$HOME/.vimrc"
|
assert_path_missing "$HOME/.vimrc"
|
||||||
assert_path_missing "$HOME/.zshrc"
|
assert_path_missing "$HOME/.zshrc"
|
||||||
@@ -147,7 +206,12 @@ run_suite() {
|
|||||||
assert_path_missing "$HOME/.config/myapp"
|
assert_path_missing "$HOME/.config/myapp"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
echo "[4/7] relink + track"
|
echo "[5/18] symlink alias"
|
||||||
|
run_homesick "symlink parity-castle"
|
||||||
|
assert_symlink_target "$HOME/.vimrc" "$HOME/.homesick/repos/parity-castle/home/.vimrc"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[6/18] relink + track"
|
||||||
run_homesick "link parity-castle"
|
run_homesick "link parity-castle"
|
||||||
setup_local_test_file
|
setup_local_test_file
|
||||||
run_homesick "track $HOME/.local/bin/tool parity-castle"
|
run_homesick "track $HOME/.local/bin/tool parity-castle"
|
||||||
@@ -156,7 +220,7 @@ run_suite() {
|
|||||||
grep -q "^.local/bin$" "$HOME/.homesick/repos/parity-castle/.homesick_subdir" || fail "expected .homesick_subdir to contain .local/bin"
|
grep -q "^.local/bin$" "$HOME/.homesick/repos/parity-castle/.homesick_subdir" || fail "expected .homesick_subdir to contain .local/bin"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
echo "[5/7] list and show_path"
|
echo "[7/18] list and show_path"
|
||||||
local list_output
|
local list_output
|
||||||
run_homesick "list"
|
run_homesick "list"
|
||||||
list_output="$RUN_OUTPUT"
|
list_output="$RUN_OUTPUT"
|
||||||
@@ -164,10 +228,10 @@ run_suite() {
|
|||||||
local show_path_output
|
local show_path_output
|
||||||
run_homesick "show_path parity-castle"
|
run_homesick "show_path parity-castle"
|
||||||
show_path_output="$RUN_OUTPUT"
|
show_path_output="$RUN_OUTPUT"
|
||||||
[[ "$show_path_output" == *"$HOME/.homesick/repos/parity-castle"* ]] || fail "expected show_path output to include parity-castle path"
|
[[ "$show_path_output" == "$HOME/.homesick/repos/parity-castle" ]] || fail "expected show_path output to equal parity-castle root path"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
echo "[6/7] status and diff"
|
echo "[8/18] status and diff"
|
||||||
echo "change" >> "$HOME/.vimrc"
|
echo "change" >> "$HOME/.vimrc"
|
||||||
local status_output
|
local status_output
|
||||||
run_homesick "status parity-castle"
|
run_homesick "status parity-castle"
|
||||||
@@ -179,7 +243,78 @@ run_suite() {
|
|||||||
[[ "$diff_output" == *"diff --git"* ]] || fail "expected diff output to include git diff"
|
[[ "$diff_output" == *"diff --git"* ]] || fail "expected diff output to include git diff"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
echo "[7/7] version"
|
echo "[9/18] pull --all"
|
||||||
|
local pull_all_output
|
||||||
|
run_homesick "pull --all"
|
||||||
|
pull_all_output="$RUN_OUTPUT"
|
||||||
|
[[ "$pull_all_output" == *"parity-castle:"* ]] || fail "expected pull --all output to include parity-castle"
|
||||||
|
[[ "$pull_all_output" == *"parity-castle-2:"* ]] || fail "expected pull --all output to include parity-castle-2"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[10/18] single-castle pull"
|
||||||
|
pushd "$work_root/base" >/dev/null
|
||||||
|
echo "single-castle-pull" > home/.pull-single
|
||||||
|
run_git add .
|
||||||
|
run_git commit -m "single-castle pull fixture"
|
||||||
|
run_git push
|
||||||
|
popd >/dev/null
|
||||||
|
run_homesick "pull parity-castle"
|
||||||
|
assert_path_exists "$HOME/.homesick/repos/parity-castle/home/.pull-single"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[11/18] exec"
|
||||||
|
local exec_marker="$HOME/.homesick/repos/parity-castle/.exec-marker"
|
||||||
|
run_homesick "exec parity-castle touch .exec-marker"
|
||||||
|
assert_path_exists "$exec_marker"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[12/18] exec_all"
|
||||||
|
local exec_all_marker_a="$HOME/.homesick/repos/parity-castle/.exec-all-marker"
|
||||||
|
local exec_all_marker_b="$HOME/.homesick/repos/parity-castle-2/.exec-all-marker"
|
||||||
|
run_homesick "exec_all touch .exec-all-marker"
|
||||||
|
assert_path_exists "$exec_all_marker_a"
|
||||||
|
assert_path_exists "$exec_all_marker_b"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[13/18] generate"
|
||||||
|
local generated_castle="$HOME/generated-castle"
|
||||||
|
run_homesick "generate $generated_castle"
|
||||||
|
assert_path_exists "$generated_castle/.git"
|
||||||
|
assert_path_exists "$generated_castle/home"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[14/18] commit and push"
|
||||||
|
echo "commit-change" >> "$HOME/.zshrc"
|
||||||
|
run_homesick "commit parity-castle behavior-suite-commit"
|
||||||
|
run_homesick "push parity-castle"
|
||||||
|
local remote_head
|
||||||
|
remote_head="$(git --git-dir "$remote_root/base.git" log --oneline -1)"
|
||||||
|
[[ "$remote_head" == *"behavior-suite-commit"* ]] || fail "expected pushed commit in remote history"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[15/18] open"
|
||||||
|
run_homesick_with_env "EDITOR=true" "open parity-castle"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[16/18] cd"
|
||||||
|
run_homesick_with_env "SHELL=/bin/true" "cd parity-castle"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[17/18] rc --force"
|
||||||
|
local rc_marker="$HOME/rc-force-was-here"
|
||||||
|
cat > "$HOME/.homesick/repos/parity-castle/.homesickrc" <<EOF
|
||||||
|
File.write('$rc_marker', 'ok\n')
|
||||||
|
EOF
|
||||||
|
run_homesick "rc --force parity-castle"
|
||||||
|
assert_path_exists "$rc_marker"
|
||||||
|
pass
|
||||||
|
|
||||||
|
echo "[18/18] destroy confirmation + version"
|
||||||
|
run_homesick_with_stdin "n\n" "destroy parity-castle"
|
||||||
|
assert_path_exists "$HOME/.homesick/repos/parity-castle"
|
||||||
|
run_homesick_with_stdin "y\n" "destroy parity-castle"
|
||||||
|
assert_path_missing "$HOME/.homesick/repos/parity-castle"
|
||||||
|
assert_path_missing "$HOME/.vimrc"
|
||||||
local version_output
|
local version_output
|
||||||
run_homesick "version"
|
run_homesick "version"
|
||||||
version_output="$RUN_OUTPUT"
|
version_output="$RUN_OUTPUT"
|
||||||
|
|||||||
Reference in New Issue
Block a user