From e83724ab1c801d6754ffe6311fd37719d016139a Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 9 Jun 2016 14:08:39 +0200 Subject: [PATCH 1/7] Add some basic tests. --- .travis.yml | 5 ++- Makefile | 4 +- test/fixtures/vimcat-help.txt | 21 +++++++++++ test/fixtures/vimpager-help.txt | 22 +++++++++++ test/help-and-version-output.bats | 62 +++++++++++++++++++++++++++++++ test/helpers.bash | 9 +++++ 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/vimcat-help.txt create mode 100644 test/fixtures/vimpager-help.txt create mode 100644 test/help-and-version-output.bats create mode 100644 test/helpers.bash diff --git a/.travis.yml b/.travis.yml index 6487cc6..e79fbb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,7 @@ dist: trusty install: - sudo make install-deb - scripts/update_lintian -script: lintian --profile debian -i --fail-on-warnings -EvIL +pedantic ../vimpager*.changes + - sudo apt-get install bats +script: + - lintian --profile debian -i --fail-on-warnings -EvIL +pedantic ../vimpager*.changes + - make test diff --git a/Makefile b/Makefile index 4dfeef2..1dfa2b1 100644 --- a/Makefile +++ b/Makefile @@ -279,6 +279,8 @@ html/%.html: %.md.work realclean distclean clean: rm -rf *.work */*.work *-stamp *-version.txt *.deb *.tar.gz *.configured *.uu */*.uu man html standalone */with_meta_* -.PHONY: all install install-deb uninstall docs realclean distclean clean +test: + bats test +.PHONY: all install install-deb uninstall docs realclean distclean clean test # vim: sw=4 diff --git a/test/fixtures/vimcat-help.txt b/test/fixtures/vimcat-help.txt new file mode 100644 index 0000000..5b70d13 --- /dev/null +++ b/test/fixtures/vimcat-help.txt @@ -0,0 +1,21 @@ +Usage: vimcat [OPTION]... [FILE | -]... +Display FILE(s) in the terminal with vim syntax highlighting using ANSI escape codes. + +With no FILE, or when FILE is -, read standard input. + + -h, --help, --usage This help screen. + -v, --version Show version information and exit. + -n Print with line numbers. + -s Squeeze multiple blank lines into one. + -o FILE | - Output ANSI highlighted text to FILE or standard output. + --cmd COMMAND Run vim COMMAND before initialization. + -c COMMAND Run vim COMMAND after initialization. + -u FILE Use FILE as the vimrc. + -x  Give debugging output on stderr. + +Examples: + vimcat program.py # output program.py with highlighting to terminal + +Project homepage: <http://github.com/rkitover/vimpager> +and documentation: <https://github.com/rkitover/vimpager/blob/master/markdown/vimcat.md> +or available locally via: man vimcat diff --git a/test/fixtures/vimpager-help.txt b/test/fixtures/vimpager-help.txt new file mode 100644 index 0000000..99e9a58 --- /dev/null +++ b/test/fixtures/vimpager-help.txt @@ -0,0 +1,22 @@ +Usage: vimpager [OPTION]... [FILE | -]... +Display FILE(s) in vim with a pager emulating less. + +With no FILE, or when FILE is -, read standard input. + + -h, --help, --usage Show this help screen and exit. + -v, --version Show version information and exit. + +G, + Go to the end of the file. + -N, --LINE-NUMBERS Show line numbers. + -s Squeeze multiple blank lines into one. + --cmd COMMAND Run vim COMMAND before initialization. + -c COMMAND Run vim COMMAND after initialization. + -u FILE Use FILE as the vimrc. + -x  Give debugging output on stderr. + +Examples: + vimpager program.py # view program.py in the pager + PAGER=vimpager man 3 sprintf # view man page for sprintf(3) + +Project homepage and documentation: <http://github.com/rkitover/vimpager> +or available locally via: man vimpager +Press ',h' for a summary of keystrokes in the program. diff --git a/test/help-and-version-output.bats b/test/help-and-version-output.bats new file mode 100644 index 0000000..043ad9a --- /dev/null +++ b/test/help-and-version-output.bats @@ -0,0 +1,62 @@ +#!/usr/bin/env bats + +load helpers + +teardown () { + rm -f output.* +} + +@test "vimpager help output of the git version" { + script -q -e -c './vimpager -h' output.1 + sed 1d output.1 > output.2 + run diff output.2 "$fixtures/vimpager-help.txt" + status_ok + no_output +} +@test "vimpager help output of the standalone version" { + script -q -e -c './standalone/vimpager -h' output.1 + sed 1d output.1 > output.2 + run diff output.2 "$fixtures/vimpager-help.txt" + status_ok + no_output +} +@test "vimpager version output of the git version" { + script -q -e -c './vimpager -v' output.1 + run sed 1d output.1 + status_ok + [[ "$output" =~ vimpager.*\(git\) ]] +} +@test "vimpager version output of the standalone version" { + script -q -e -c './standalone/vimpager -v' output.1 + run sed 1d output.1 + status_ok + [[ "$output" =~ vimpager.*\(standalone,\ shell=.*\) ]] +} +@test "vimcat help output of the git version" { + script -q -e -c './vimcat -h' output.1 + sed 1d output.1 > output.2 + run diff output.2 "$fixtures/vimcat-help.txt" + status_ok + no_output +} +@test "vimcat help output of the standalone version" { + script -q -e -c './standalone/vimcat -h' output.1 + sed 1d output.1 > output.2 + run diff output.2 "$fixtures/vimcat-help.txt" + status_ok + no_output +} +@test "vimcat version output of the git version" { + script -q -e -c './vimcat -v' output.1 + run sed 1d output.1 + status_ok + [[ "$output" =~ vimcat.*\(git\) ]] +} +@test "vimcat version output of the standalone version" { + script -q -e -c './standalone/vimcat -v' output.1 + run sed 1d output.1 + status_ok + [[ "$output" =~ vimcat.*\(standalone,\ shell=.*\) ]] +} + +# vim: filetype=sh diff --git a/test/helpers.bash b/test/helpers.bash new file mode 100644 index 0000000..7c3b4a3 --- /dev/null +++ b/test/helpers.bash @@ -0,0 +1,9 @@ +#!bash + +fixtures=$BATS_TEST_DIRNAME/fixtures +status_ok () { + [ "$status" -eq 0 ] +} +no_output () { + [ -z "$output" ] +} From e9c7f1fb8b3ccc50cfcb9419a612754e6497ccb4 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Fri, 10 Jun 2016 11:43:22 +0200 Subject: [PATCH 2/7] Build standalone scripts before running tests. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1dfa2b1..e48d9b5 100644 --- a/Makefile +++ b/Makefile @@ -279,7 +279,7 @@ html/%.html: %.md.work realclean distclean clean: rm -rf *.work */*.work *-stamp *-version.txt *.deb *.tar.gz *.configured *.uu */*.uu man html standalone */with_meta_* -test: +test: standalone/vimpager standalone/vimcat bats test .PHONY: all install install-deb uninstall docs realclean distclean clean test From 1c921871f36afb1fdbe2eb276d74f47dc6bff5a2 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Fri, 10 Jun 2016 11:50:58 +0200 Subject: [PATCH 3/7] Add test with symlinks for #193. --- ...sourced-files-with-symlinks-to-script.bats | 22 +++++++++++++++++++ .../bin/vimcat-relative-symlink-to-git | 1 + .../bin/vimpager-relative-symlink-to-git | 1 + 3 files changed, 24 insertions(+) create mode 100644 test/find-sourced-files-with-symlinks-to-script.bats create mode 120000 test/fixtures/bin/vimcat-relative-symlink-to-git create mode 120000 test/fixtures/bin/vimpager-relative-symlink-to-git diff --git a/test/find-sourced-files-with-symlinks-to-script.bats b/test/find-sourced-files-with-symlinks-to-script.bats new file mode 100644 index 0000000..b7e2c2e --- /dev/null +++ b/test/find-sourced-files-with-symlinks-to-script.bats @@ -0,0 +1,22 @@ +#!/usr/bin/env bats + +load helpers + +teardown () { + rm -f output.* +} + +@test "symlink to vimpager finds the correct project directory" { + script -q -e -c "$fixtures/bin/vimpager-relative-symlink-to-git -v" output.1 + run sed 1d output.1 + status_ok + [[ "$output" =~ vimpager.*\(git\) ]] +} +@test "symlink to vimcat finds the correct project directory" { + script -q -e -c "$fixtures/bin/vimcat-relative-symlink-to-git -v" output.1 + run sed 1d output.1 + status_ok + [[ "$output" =~ vimcat.*\(git\) ]] +} + +# vim: filetype=sh diff --git a/test/fixtures/bin/vimcat-relative-symlink-to-git b/test/fixtures/bin/vimcat-relative-symlink-to-git new file mode 120000 index 0000000..86b534d --- /dev/null +++ b/test/fixtures/bin/vimcat-relative-symlink-to-git @@ -0,0 +1 @@ +../../../vimcat \ No newline at end of file diff --git a/test/fixtures/bin/vimpager-relative-symlink-to-git b/test/fixtures/bin/vimpager-relative-symlink-to-git new file mode 120000 index 0000000..5af802a --- /dev/null +++ b/test/fixtures/bin/vimpager-relative-symlink-to-git @@ -0,0 +1 @@ +../../../vimpager \ No newline at end of file From 7f841dfb0b5a6ad5f6ece5ba25cb7585da9249c6 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Mon, 20 Jun 2016 05:59:56 +0200 Subject: [PATCH 4/7] Fix travis build - Move `make install-deb` to the script step as it runs the tests. - Install uuencode (package sharutils) explicitly as it is needed during testing. Formally it was implicitly installed by `make install-deb`. - Install bats manually as there is no package for it on trusty. - Remove bats building directory as it is reported by lintian. - Fetch git tags as they are needed to run the tests. - Run `make all`. - Add a modeline. --- .travis.yml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e79fbb2..9f2574f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,29 @@ sudo: required dist: trusty + install: - - sudo make install-deb - scripts/update_lintian - - sudo apt-get install bats + # apt-get update was already run by the update_lintian script. + - sudo apt-get install sharutils + # Install the test suite manually as there is no package for it on trusty. + - ( git clone https://github.com/sstephenson/bats.git && cd bats && sudo ./install.sh /usr/local ) + +before_script: + # The version output of vimpager depends of the tags in the repository so + # we need to fetch them before running the tests. Currently all tags are + # fetched. TODO: Only fetch the latest tag. + - git fetch --unshallow --tags + # The bats directory is only needed during the manual installation above. + # It would be reported by lintian otherwise. + - rm -fr bats + + script: - - lintian --profile debian -i --fail-on-warnings -EvIL +pedantic ../vimpager*.changes + - make all - make test + # The target install-deb also runs the tests (via dpkg-buildpackage) so it + # sould not be run during the travis "install" step. + - sudo make install-deb + - lintian --profile debian -i --fail-on-warnings -EvIL +pedantic ../vimpager*.changes + +# vim: sw=4 From a3b0b94895c5ad336120012b5629f6ed8e2b4d8b Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Mon, 20 Jun 2016 10:59:18 +0200 Subject: [PATCH 5/7] Add tests to copyright info --- debian/copyright | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/copyright b/debian/copyright index 56a3a12..91529f2 100644 --- a/debian/copyright +++ b/debian/copyright @@ -3,7 +3,7 @@ Upstream-Name: vimpager Upstream-Contact: Rafael Kitover Source: http://github.com/rkitover/vimpager -Files: vimpager vimcat vimpagerrc *.yml .travis.yml Makefile markdown_src/*.md markdown/*.md autoload/vimpager.vim autoload/vimpager_utils.vim plugin/vimpager.vim prototypes/* prototypes/*/* scripts/* inc/* +Files: vimpager vimcat vimpagerrc *.yml .travis.yml Makefile markdown_src/*.md markdown/*.md autoload/vimpager.vim autoload/vimpager_utils.vim plugin/vimpager.vim prototypes/* prototypes/*/* scripts/* inc/* test/* Copyright: 2016 Rafael Kitover License: BSD-2-Clause From 683bf689b2ffa2cb6c356f1dcbe82b5094a7c577 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Fri, 24 Jun 2016 00:48:13 +0200 Subject: [PATCH 6/7] Use env variables to improve build on travis --- .travis.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f2574f..68d910d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,11 @@ sudo: required dist: trusty install: + # Update to a new version of lintian as the one on trusty is quite old. + # This also runs apt-get update. - scripts/update_lintian - # apt-get update was already run by the update_lintian script. - - sudo apt-get install sharutils # Install the test suite manually as there is no package for it on trusty. - - ( git clone https://github.com/sstephenson/bats.git && cd bats && sudo ./install.sh /usr/local ) + - ( git clone https://github.com/sstephenson/bats.git && cd bats && ./install.sh ~/.local ) before_script: # The version output of vimpager depends of the tags in the repository so @@ -19,11 +19,14 @@ before_script: script: + # The target install-deb also installs the sharutils package that contains + # uuencode. Without DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage (which is + # run by install-deb) would also run the tests. + - sudo make install-deb CLEAN_BUILD_DEPS=0 DEB_BUILD_OPTIONS=nocheck + # lintian has to be run after make install-deb as it needs the file that + # are created by the makefile. + - lintian --profile debian -i --fail-on-warnings -EvIL +pedantic ../vimpager*.changes - make all - make test - # The target install-deb also runs the tests (via dpkg-buildpackage) so it - # sould not be run during the travis "install" step. - - sudo make install-deb - - lintian --profile debian -i --fail-on-warnings -EvIL +pedantic ../vimpager*.changes # vim: sw=4 From 5c0827943fcbaa06ed8bf2baf210e866dfe85cfd Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Fri, 24 Jun 2016 01:07:07 +0200 Subject: [PATCH 7/7] Silence apt-get in the makefile and script --- Makefile | 6 +++--- scripts/update_lintian | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index e48d9b5..7e0e3bb 100644 --- a/Makefile +++ b/Makefile @@ -198,8 +198,8 @@ install-deb: echo >&2; \ exit 1; \ fi - @apt-get update || true - @apt-get -y install debhelper devscripts equivs gdebi-core + @-apt-get -qq update + @apt-get -yqq install debhelper devscripts equivs gdebi-core @mk-build-deps @echo y | gdebi vimpager-build-deps*.deb @rm -f vimpager-build-deps*.deb @@ -210,7 +210,7 @@ install-deb: @dpkg-buildpackage -us -uc @echo y | gdebi `ls -1t ../vimpager*deb | head -1` @dpkg --purge vimpager-build-deps - @[ "$${CLEAN_BUILD_DEPS:-1}" -ne 0 ] && apt-get -y autoremove || true + @-[ "$${CLEAN_BUILD_DEPS:-1}" -ne 0 ] && apt-get -yqq autoremove @debian/rules clean docs: ${GEN_DOCS} docs.tar.gz Makefile diff --git a/scripts/update_lintian b/scripts/update_lintian index 97b96aa..80e5d1a 100755 --- a/scripts/update_lintian +++ b/scripts/update_lintian @@ -1,9 +1,9 @@ #!/bin/sh -sudo apt-get update || true -sudo apt-get -y install debian-archive-keyring +sudo apt-get -yqq update +sudo apt-get -yqq install debian-archive-keyring sudo sh -c "echo 'deb-src http://httpredir.debian.org/debian unstable main' > /etc/apt/sources.list.d/debian-src.list" -sudo apt-get update || true +sudo apt-get -qq update export DEB_BUILD_OPTIONS=nocheck