fix the tests to create new session and return to it after the test is done
This commit is contained in:
parent
780e72f940
commit
a89ffe7f1e
6 changed files with 26 additions and 16 deletions
0
.brew_lists/.gitingnore
Normal file → Executable file
0
.brew_lists/.gitingnore
Normal file → Executable file
0
.brew_lists/brew_list.txt.new
Normal file → Executable file
0
.brew_lists/brew_list.txt.new
Normal file → Executable file
0
.brew_lists/cask_list.txt.new
Normal file → Executable file
0
.brew_lists/cask_list.txt.new
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
|
|
@ -1,5 +1,11 @@
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
cleanup_session() {
|
||||||
|
tmux kill-session -t "$SESSION_NAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap 'cleanup_session' EXIT
|
||||||
|
|
||||||
@test "Script creates a tmux session" {
|
@test "Script creates a tmux session" {
|
||||||
TMP_DIR=$(mktemp -d)
|
TMP_DIR=$(mktemp -d)
|
||||||
ORIGINAL_SESSION=$(tmux display-message -p "#S")
|
ORIGINAL_SESSION=$(tmux display-message -p "#S")
|
||||||
|
|
@ -20,7 +26,7 @@
|
||||||
# Return to the original session
|
# Return to the original session
|
||||||
tmux switch-client -n -t="$ORIGINAL_SESSION"
|
tmux switch-client -n -t="$ORIGINAL_SESSION"
|
||||||
|
|
||||||
# Clean up
|
# Clean up (Note: This line is no longer necessary)
|
||||||
tmux kill-session -t="$SESSION_NAME"
|
# tmux kill-session -t="$SESSION_NAME"
|
||||||
rm -r "$TMP_DIR"
|
rm -r "$TMP_DIR"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,29 @@
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
cleanup_session() {
|
||||||
|
# Remove the test session
|
||||||
|
tmux kill-session -t "$SESSION_NAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap 'cleanup_session' EXIT
|
||||||
|
|
||||||
@test "Script creates a new tmux window with the correct branch name" {
|
@test "Script creates a new tmux window with the correct branch name" {
|
||||||
BRANCH_NAME="test_branch"
|
BRANCH_NAME="test_branch"
|
||||||
SESSION_NAME="test_session"
|
SESSION_NAME="test_session"
|
||||||
|
|
||||||
|
# Get the original session name
|
||||||
|
ORIGINAL_SESSION=$(tmux display-message -p "#S")
|
||||||
|
|
||||||
# Check if the created session exists
|
# Check if the created session exists
|
||||||
run tmux has-session -t "$SESSION_NAME"
|
run tmux has-session -t "$SESSION_NAME"
|
||||||
|
|
||||||
if [ "$status" -ne 0 ]; then
|
if [ "$status" -ne 0 ]; then
|
||||||
# Create a new tmux session if it doesn't exist
|
# Create a new tmux session if it doesn't exist
|
||||||
run tmux new-session -d -s "$SESSION_NAME"
|
tmux new-session -d -s "$SESSION_NAME"
|
||||||
# Check if the session was created successfully
|
fi
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
|
|
||||||
# Switch into the new test session
|
# Rename window to branch name regardless of session creation
|
||||||
if [ "$status" -eq 0 ]; then
|
tmux rename-window -t "$SESSION_NAME" "$BRANCH_NAME"
|
||||||
run tmux switch-client -t "$SESSION_NAME"
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run your script with predefined branch name and session name
|
# Run your script with predefined branch name and session name
|
||||||
run ./tmux_windownizer "$BRANCH_NAME"
|
run ./tmux_windownizer "$BRANCH_NAME"
|
||||||
|
|
@ -27,14 +32,13 @@
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
# Check if tmux window was created
|
# Check if tmux window was created
|
||||||
run tmux list-windows -t="$SESSION_NAME" | grep "$BRANCH_NAME"
|
tmux list-windows -t="$SESSION_NAME" | grep -q "$BRANCH_NAME"
|
||||||
[ "$status" -eq 0 ]
|
[ "$?" -eq 0 ]
|
||||||
|
|
||||||
# Remove the created tmux window
|
# Remove the created tmux window
|
||||||
run tmux kill-window -t "$SESSION_NAME:$BRANCH_NAME"
|
run tmux kill-window -t "$SESSION_NAME:$BRANCH_NAME"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
# Remove the test session
|
# Return to the original session
|
||||||
run tmux kill-session -t "$SESSION_NAME"
|
tmux switch-client -n -t "$ORIGINAL_SESSION"
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue