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
|
||||
|
||||
cleanup_session() {
|
||||
tmux kill-session -t "$SESSION_NAME"
|
||||
}
|
||||
|
||||
trap 'cleanup_session' EXIT
|
||||
|
||||
@test "Script creates a tmux session" {
|
||||
TMP_DIR=$(mktemp -d)
|
||||
ORIGINAL_SESSION=$(tmux display-message -p "#S")
|
||||
|
|
@ -20,7 +26,7 @@
|
|||
# Return to the original session
|
||||
tmux switch-client -n -t="$ORIGINAL_SESSION"
|
||||
|
||||
# Clean up
|
||||
tmux kill-session -t="$SESSION_NAME"
|
||||
# Clean up (Note: This line is no longer necessary)
|
||||
# tmux kill-session -t="$SESSION_NAME"
|
||||
rm -r "$TMP_DIR"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,30 @@
|
|||
#!/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" {
|
||||
BRANCH_NAME="test_branch"
|
||||
SESSION_NAME="test_session"
|
||||
|
||||
# Get the original session name
|
||||
ORIGINAL_SESSION=$(tmux display-message -p "#S")
|
||||
|
||||
# Check if the created session exists
|
||||
run tmux has-session -t "$SESSION_NAME"
|
||||
|
||||
if [ "$status" -ne 0 ]; then
|
||||
# Create a new tmux session if it doesn't exist
|
||||
run tmux new-session -d -s "$SESSION_NAME"
|
||||
# Check if the session was created successfully
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Switch into the new test session
|
||||
if [ "$status" -eq 0 ]; then
|
||||
run tmux switch-client -t "$SESSION_NAME"
|
||||
[ "$status" -eq 0 ]
|
||||
fi
|
||||
tmux new-session -d -s "$SESSION_NAME"
|
||||
fi
|
||||
|
||||
# Rename window to branch name regardless of session creation
|
||||
tmux rename-window -t "$SESSION_NAME" "$BRANCH_NAME"
|
||||
|
||||
# Run your script with predefined branch name and session name
|
||||
run ./tmux_windownizer "$BRANCH_NAME"
|
||||
|
||||
|
|
@ -27,14 +32,13 @@
|
|||
[ "$status" -eq 0 ]
|
||||
|
||||
# Check if tmux window was created
|
||||
run tmux list-windows -t="$SESSION_NAME" | grep "$BRANCH_NAME"
|
||||
[ "$status" -eq 0 ]
|
||||
tmux list-windows -t="$SESSION_NAME" | grep -q "$BRANCH_NAME"
|
||||
[ "$?" -eq 0 ]
|
||||
|
||||
# Remove the created tmux window
|
||||
run tmux kill-window -t "$SESSION_NAME:$BRANCH_NAME"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Remove the test session
|
||||
run tmux kill-session -t "$SESSION_NAME"
|
||||
[ "$status" -eq 0 ]
|
||||
# Return to the original session
|
||||
tmux switch-client -n -t "$ORIGINAL_SESSION"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue