From d8b8dff61f355d55b63476e55316fbe4363ab765 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 4 Jun 2014 00:36:33 +0100 Subject: [PATCH] Add tests for new_window layout helper --- test/lib/layout-helpers/new_window.test.sh | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 test/lib/layout-helpers/new_window.test.sh diff --git a/test/lib/layout-helpers/new_window.test.sh b/test/lib/layout-helpers/new_window.test.sh new file mode 100755 index 0000000..2507f43 --- /dev/null +++ b/test/lib/layout-helpers/new_window.test.sh @@ -0,0 +1,47 @@ +#! /usr/bin/env bash +source "../../test-helper.sh" +source "${root}/lib/layout-helpers.sh" + +# +# new_window() tests. +# + +# When called without arguments, creates new window. +create-test-session +stub __go_to_window_or_session_path +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" +new_window +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" +assert "stub_called_times __go_to_window_or_session_path" "1" +restore __go_to_window_or_session_path +kill-test-session + +# When called with name argument, creates new window with specified name. +create-test-session +stub __go_to_window_or_session_path +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" +assert "test-socket-tmux list-windows | grep yippieezzz | wc -l | awk '{print \$1}'" "0" +new_window "yippieezzz" +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" +assert "test-socket-tmux list-windows | grep yippieezzz | wc -l | awk '{print \$1}'" "1" +restore __go_to_window_or_session_path +kill-test-session + +# When called with name and command argument, creates new window with +# specified name and executes given command. +rm "/tmp/tmuxifier-new_window-test" &> /dev/null +create-test-session +stub __go_to_window_or_session_path +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" +assert "test-socket-tmux list-windows | grep foobardoo | wc -l | awk '{print \$1}'" "0" +new_window "foobardoo" "touch /tmp/tmuxifier-new_window-test; bash" +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" +assert "test-socket-tmux list-windows | grep foobardoo | wc -l | awk '{print \$1}'" "1" +assert_raises 'test -f "/tmp/tmuxifier-new_window-test"' 0 +restore __go_to_window_or_session_path +kill-test-session +rm "/tmp/tmuxifier-new_window-test" &> /dev/null + + +# End of tests. +assert_end "new_window()"