aboutsummaryrefslogtreecommitdiff
path: root/plugins/tpm/tests/test_plugin_clean.sh
blob: d36c468cc26cd493adfcad3ab9d834cb9dbb8115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TPM_DIR="$PWD"
PLUGINS_DIR="$HOME/.tmux/plugins"

source "$CURRENT_DIR/helpers/helpers.sh"
source "$CURRENT_DIR/helpers/tpm.sh"

manually_install_the_plugin() {
	rm -rf "$PLUGINS_DIR"
	mkdir -p "$PLUGINS_DIR"
	cd "$PLUGINS_DIR"
	git clone --quiet https://github.com/tmux-plugins/tmux-example-plugin
}

# TMUX KEY-BINDING TESTS

test_plugin_uninstallation_via_tmux_key_binding() {
	set_tmux_conf_helper <<- HERE
	set -g mode-keys vi
	run-shell "$TPM_DIR/tpm"
	HERE

	manually_install_the_plugin

	"$CURRENT_DIR/expect_successful_clean_plugins" ||
		fail_helper "[key-binding] clean fails"

	teardown_helper
}

# SCRIPT TESTS

test_plugin_uninstallation_via_script() {
	set_tmux_conf_helper <<- HERE
	set -g mode-keys vi
	run-shell "$TPM_DIR/tpm"
	HERE

	manually_install_the_plugin

	script_run_helper "$TPM_DIR/bin/clean_plugins" '"tmux-example-plugin" clean success' ||
		fail_helper "[script] plugin cleaning fails"

	teardown_helper
}

test_unsuccessful_plugin_uninstallation_via_script() {
	set_tmux_conf_helper <<- HERE
	set -g mode-keys vi
	run-shell "$TPM_DIR/tpm"
	HERE

	manually_install_the_plugin
	chmod 000 "$PLUGINS_DIR/tmux-example-plugin" # disable directory deletion

	local expected_exit_code=1
	script_run_helper "$TPM_DIR/bin/clean_plugins" '"tmux-example-plugin" clean fail' "$expected_exit_code" ||
		fail_helper "[script] unsuccessful plugin cleaning doesn't fail"

	chmod 755 "$PLUGINS_DIR/tmux-example-plugin" # enable directory deletion

	teardown_helper
}

run_tests