diff --git a/README.md b/README.md index 3dc8a96..c6f0e6c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # tmux-fingers +[![CircleCI](https://circleci.com/gh/Morantron/tmux-fingers.svg?style=svg)](https://circleci.com/gh/Morantron/tmux-fingers) + **tmux-fingers**: copy pasting with vimium/vimperator like hints. ![yay](http://i.imgur.com/5bSrBew.gif) diff --git a/Vagrantfile b/Vagrantfile index 154a2bc..6036806 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,11 +4,20 @@ # requires nfs-utils on host Vagrant.configure(2) do |config| - config.vm.box = "freebsd/FreeBSD-11.0-CURRENT" - config.ssh.shell = "/bin/sh" + config.vm.define "bsd" do |machine| + machine.vm.box = "freebsd/FreeBSD-10.3-RELEASE" + machine.ssh.shell = "/bin/sh" - config.vm.network "private_network", ip: "10.0.1.10", mac: "5CA1AB1E0001" - config.vm.synced_folder ".", "/home/vagrant/shared", :nfs => true + machine.vm.base_mac = "080027D14C66" + machine.vm.network "private_network", ip: "10.0.1.10", mac: "5CA1AB1E0001" + machine.vm.synced_folder ".", "/home/vagrant/shared", :nfs => true - config.vm.provision "shell", path: './test/bsd_provisioning.sh' + machine.vm.provision "shell", path: './test/provisioning/bsd.sh' + end + + config.vm.define "ubuntu" do |machine| + machine.vm.box = "ubuntu/trusty64" + machine.vm.synced_folder ".", "/home/vagrant/shared" + machine.vm.provision "shell", path: './test/provisioning/ubuntu.sh' + end end diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..dde07e8 --- /dev/null +++ b/circle.yml @@ -0,0 +1,8 @@ +dependencies: + pre: + - if [[ ! -e tmux-2.2 ]]; then sudo bash ./test/provisioning/ubuntu.sh; fi + - sudo mkdir -p /home/vagrant/ && sudo chmod a+w /home/vagrant && ln -s $(pwd) /home/vagrant/shared + - tmux -V +test: + override: + - ./test/run.sh within-vm diff --git a/test/conf/basic.conf b/test/conf/basic.conf new file mode 100644 index 0000000..79e8ec5 --- /dev/null +++ b/test/conf/basic.conf @@ -0,0 +1,2 @@ +set -g prefix C-a +run /home/vagrant/shared/tmux-fingers.tmux diff --git a/test/conf/custom-bindings.conf b/test/conf/custom-bindings.conf new file mode 100644 index 0000000..6e3cd3d --- /dev/null +++ b/test/conf/custom-bindings.conf @@ -0,0 +1,4 @@ +set -g prefix C-Space +set -g mode-keys vi + +run /home/vagrant/shared/tmux-fingers.tmux diff --git a/test/fixtures/grep-output b/test/fixtures/grep-output new file mode 100644 index 0000000..46ef43f --- /dev/null +++ b/test/fixtures/grep-output @@ -0,0 +1,2 @@ +scripts/debug.sh:# Source this file and call `tail -f fingers.log` when you don't know WTF is +scripts/hints.sh:IFS=$(echo -en "\n\b") # wtf bash? diff --git a/test/fixtures/ip-output b/test/fixtures/ip-output new file mode 100644 index 0000000..8e014ff --- /dev/null +++ b/test/fixtures/ip-output @@ -0,0 +1,18 @@ +1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + inet 127.0.0.1 scope host lo + valid_lft forever preferred_lft forever + inet6 ::1 scope host + valid_lft forever preferred_lft forever +2: wlp3s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000 + link/ether 78:31:c1:d5:40:ce brd ff:ff:ff:ff:ff:ff + inet 192.168.1.39 brd 192.168.1.255 scope global dynamic wlp3s0 + valid_lft 33919sec preferred_lft 33919sec + inet6 fe80::7a31:c1ff:fed5:40ce scope link tentative dadfailed + valid_lft forever preferred_lft forever +3: vboxnet0: mtu 1500 qdisc fq_codel state DOWN group default qlen 1000 + link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff + inet 10.0.1.1 brd 10.0.1.255 scope global vboxnet0 + valid_lft forever preferred_lft forever + inet6 fe80::800:27ff:fe00:0 scope link + valid_lft forever preferred_lft forever diff --git a/test/helpers.exp b/test/helpers.exp new file mode 100644 index 0000000..3819b14 --- /dev/null +++ b/test/helpers.exp @@ -0,0 +1,55 @@ +#!/usr/bin/env expect + +set exit_code 2 + +proc test_clean_up {} { + exec "tmux kill-session -t test"; + sleep 0.5; +} + +proc exec {cmd} { + sleep 0.5; + send "$cmd"; + sleep 0.5; + send "\r"; + sleep 0.5; +} + +proc tmux_send {key} { + global tmux_prefix; + sleep 0.5; + send $tmux_prefix; + sleep 0.5; + send "$key"; + sleep 0.5; +} + +proc init_pane {} { + tmux_send "c"; + exec "export PS1='# '; clear"; +} + +proc invoke_fingers {} { + tmux_send "F"; + sleep 0.5; +} + +proc echo_yanked {} { + exec "clear"; + send "echo yanked text is "; + tmux_send "]"; + send "\r"; +} + +proc exit_ok {} { + global exit_code + set exit_code 0; + test_clean_up; +} + +proc exit_fail {} { + global exit_code + set exit_code 1; + exec "tmux list-buffers >> ./spec-output.log" + test_clean_up; +} diff --git a/test/bsd_provisioning.sh b/test/provisioning/bsd.sh similarity index 75% rename from test/bsd_provisioning.sh rename to test/provisioning/bsd.sh index 9b37308..b297b4c 100644 --- a/test/bsd_provisioning.sh +++ b/test/provisioning/bsd.sh @@ -1,6 +1,6 @@ #!/bin/sh -pkg install -y bash tmux +pkg install -y bash tmux expect chsh -s bash vagrant echo "run /home/vagrant/shared/tmux-fingers.tmux" > .tmux.conf diff --git a/test/provisioning/ubuntu.sh b/test/provisioning/ubuntu.sh new file mode 100644 index 0000000..e800e41 --- /dev/null +++ b/test/provisioning/ubuntu.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +apt-get remove -y tmux +apt-get install -y libevent-dev libncurses5-dev expect + +wget https://github.com/tmux/tmux/releases/download/2.2/tmux-2.2.tar.gz + +tar xvzf tmux-2.2.tar.gz +cd tmux-2.2/ || echo "Could not find tmux-2.2/ folder" || exit 1 + +./configure +make +make install diff --git a/test/run.sh b/test/run.sh new file mode 100755 index 0000000..eed8208 --- /dev/null +++ b/test/run.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SPEC_OUTPUT_LOG=$CURRENT_DIR/../spec-output.log +TEST_LOG=$CURRENT_DIR/../test.log +target=$1 + +cat /dev/null > $SPEC_OUTPUT_LOG +cat /dev/null > $TEST_LOG + +if [[ "$target" == "within-vm" ]]; then + fail_count=0 + for test_file in $(ls $CURRENT_DIR/specs/*_spec.exp); do + result="* $test_file ..." + sleep 1 + echo "Running $test_file" >> $SPEC_OUTPUT_LOG + $test_file &>> $TEST_LOG + + if [[ $? == 0 ]]; then + result="$result OK" + else + fail_count=$((fail_count + 1)) + result="$result FAIL" + fi + + echo "$result" >> $SPEC_OUTPUT_LOG + echo "$result" + done + + exit $fail_count +elif [[ -z "$target" ]]; then + $CURRENT_DIR/run.sh ubuntu + ubuntu_fail_count=$? + + $CURRENT_DIR/run.sh bsd + bsd_fail_count=$? + + total_fail_count=$((ubuntu_fail_count + bsd_fail_count)) + + if [[ $total_fail_count == 0 ]]; then + echo "All tests passed, awesome!" + else + echo "$total_fail_count tests failed." + cat $SPEC_OUTPUT_LOG + fi + + exit $total_fail_count +else + echo "Running tests on $target" + vagrant up "$target" &>> /dev/null + vagrant ssh "$target" -c "cd shared && ./test/run.sh within-vm" 2> /dev/null +fi diff --git a/test/specs/basic-yank_spec.exp b/test/specs/basic-yank_spec.exp new file mode 100755 index 0000000..8ea5c7f --- /dev/null +++ b/test/specs/basic-yank_spec.exp @@ -0,0 +1,23 @@ +#!/usr/bin/env expect + +set timeout 1; +set tmux_prefix ""; + +source "./test/helpers.exp" + +exec "tmux kill-session -t test"; +spawn tmux -f ./test/conf/basic.conf new -s test; +sleep 0.5; + +init_pane +exec "cat ./test/fixtures/grep-output"; +invoke_fingers; +send "i"; +echo_yanked; + +expect { + "yanked text is scripts/hints.sh" { exit_ok } + timeout { exit_fail } +} + +exit $exit_code; diff --git a/test/specs/more-than-one-match-per-line_spec.exp b/test/specs/more-than-one-match-per-line_spec.exp new file mode 100755 index 0000000..9eb1ec4 --- /dev/null +++ b/test/specs/more-than-one-match-per-line_spec.exp @@ -0,0 +1,24 @@ +#!/usr/bin/env expect + +set timeout 1; +set tmux_prefix ""; + +source "./test/helpers.exp" + +exec "tmux kill-session -t test"; +spawn tmux -f ./test/conf/basic.conf new -s test; +sleep 0.5; + +init_pane +exec "cat ./test/fixtures/ip-output"; +invoke_fingers; +send "t"; +echo_yanked; + +expect { + "yanked text is 10.0.1.255" { exit_ok } + timeout { exit_fail } +} + +exit $exit_code; + diff --git a/test/specs/works-with-custom-bindings_spec.exp b/test/specs/works-with-custom-bindings_spec.exp new file mode 100755 index 0000000..b5cc57b Binary files /dev/null and b/test/specs/works-with-custom-bindings_spec.exp differ