mirror of
				https://github.com/tmux-plugins/tpm.git
				synced 2025-11-04 00:16:05 +00:00 
			
		
		
		
	Refactor the tests for travis
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
# Changelog
 | 
			
		||||
 | 
			
		||||
### master
 | 
			
		||||
- refactor tests so they can be used on travis
 | 
			
		||||
 | 
			
		||||
### v1.1.0, 2014-11-19
 | 
			
		||||
- if the plugin is not downloaded do not source it
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								run-tests
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								run-tests
									
									
									
									
									
								
							@@ -2,6 +2,9 @@
 | 
			
		||||
 | 
			
		||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
			
		||||
 | 
			
		||||
# running test suite is successful by default
 | 
			
		||||
tests_exit_value=0
 | 
			
		||||
 | 
			
		||||
run_vagrant() {
 | 
			
		||||
	vagrant up
 | 
			
		||||
}
 | 
			
		||||
@@ -14,24 +17,15 @@ stop_vagrant() {
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test_files() {
 | 
			
		||||
	ls -1 ./tests/ |            # test files are in `./tests/` dir
 | 
			
		||||
		grep -i '^test' |       # test file names start with 'test'
 | 
			
		||||
		xargs				    # file names in one line
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
run_tests() {
 | 
			
		||||
	local test_file
 | 
			
		||||
	local test_dir_path="~/tpm/tests/"
 | 
			
		||||
	for test_file in $(test_files); do
 | 
			
		||||
		echo "Running test: $test_file"
 | 
			
		||||
		vagrant ssh -c "${test_dir_path}${test_file}"
 | 
			
		||||
	done
 | 
			
		||||
	vagrant ssh -c "cd ~/tpm; ./tests/run-tests-within-vm"
 | 
			
		||||
	tests_exit_value=$?
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main() {
 | 
			
		||||
	run_vagrant
 | 
			
		||||
	run_tests
 | 
			
		||||
	stop_vagrant
 | 
			
		||||
	exit "$tests_exit_value"
 | 
			
		||||
}
 | 
			
		||||
main
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										41
									
								
								tests/run-tests-within-vm
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										41
									
								
								tests/run-tests-within-vm
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
# A test runner file.
 | 
			
		||||
# Intended to be run from `./run-tests` script *within* a virtual machine.
 | 
			
		||||
# DO NOT run it locally as it might overwrite your `.tmux.conf` (that's what it
 | 
			
		||||
# does during the tests).
 | 
			
		||||
 | 
			
		||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
			
		||||
 | 
			
		||||
# running test suite is successful by default
 | 
			
		||||
tests_exit_value=0
 | 
			
		||||
 | 
			
		||||
set_global_exit_val_to_false() {
 | 
			
		||||
	tests_exit_value=1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test_files() {
 | 
			
		||||
	ls -1 "$CURRENT_DIR" |      # test files are in the current dir
 | 
			
		||||
		grep -i '^test' |       # test file names start with 'test'
 | 
			
		||||
		xargs                   # file names in one line
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
run_tests() {
 | 
			
		||||
	local test_file
 | 
			
		||||
	for test_file in $(test_files); do
 | 
			
		||||
		echo "Running test: $test_file"
 | 
			
		||||
		$CURRENT_DIR/$test_file
 | 
			
		||||
 | 
			
		||||
		# handling exit value
 | 
			
		||||
		local exit_value="$?"
 | 
			
		||||
		if [ "$exit_value" != 0 ]; then
 | 
			
		||||
			set_global_exit_val_to_false
 | 
			
		||||
		fi
 | 
			
		||||
	done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main() {
 | 
			
		||||
	run_tests
 | 
			
		||||
	exit "$tests_exit_value"
 | 
			
		||||
}
 | 
			
		||||
main
 | 
			
		||||
@@ -7,7 +7,7 @@ source $CURRENT_DIR/helpers.sh
 | 
			
		||||
test_plugin_installation() {
 | 
			
		||||
	set_tmux_conf_helper <<- HERE
 | 
			
		||||
	set -g @tpm_plugins "tmux-plugins/tmux-example-plugin"
 | 
			
		||||
	run-shell "~/tpm/tpm"
 | 
			
		||||
	run-shell "$PWD/tpm"
 | 
			
		||||
	HERE
 | 
			
		||||
 | 
			
		||||
	# opens tmux and test it with `expect`
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ check_binding_defined() {
 | 
			
		||||
test_plugin_sourcing() {
 | 
			
		||||
	set_tmux_conf_helper <<- HERE
 | 
			
		||||
	set -g @tpm_plugins "doesnt_matter/tmux_test_plugin"
 | 
			
		||||
	run-shell "~/tpm/tpm"
 | 
			
		||||
	run-shell "$PWD/tpm"
 | 
			
		||||
	HERE
 | 
			
		||||
 | 
			
		||||
	# manually creates a local tmux plugin
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ manually_install_the_plugin() {
 | 
			
		||||
test_plugin_installation() {
 | 
			
		||||
	set_tmux_conf_helper <<- HERE
 | 
			
		||||
	set -g @tpm_plugins "tmux-plugins/tmux-example-plugin"
 | 
			
		||||
	run-shell "~/tpm/tpm"
 | 
			
		||||
	run-shell "$PWD/tpm"
 | 
			
		||||
	HERE
 | 
			
		||||
 | 
			
		||||
	manually_install_the_plugin
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user