diff --git a/.travis.yml b/.travis.yml index 6487cc6..68d910d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,32 @@ sudo: required dist: trusty + install: - - sudo make install-deb + # Update to a new version of lintian as the one on trusty is quite old. + # This also runs apt-get update. - scripts/update_lintian -script: lintian --profile debian -i --fail-on-warnings -EvIL +pedantic ../vimpager*.changes + # Install the test suite manually as there is no package for it on trusty. + - ( 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 + # 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: + # 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 + +# vim: sw=4 diff --git a/Makefile b/Makefile index 4dfeef2..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 @@ -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: standalone/vimpager standalone/vimcat + bats test +.PHONY: all install install-deb uninstall docs realclean distclean clean test # vim: sw=4 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 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 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 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" ] +}