diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rwxr-xr-x | tests/remotes.sh | 176 |
3 files changed, 179 insertions, 0 deletions
@@ -2,3 +2,5 @@ /git-permalink /doc/*.mo /doc/*.po~ +/tests/remotes/ +/tests/prefix/ @@ -16,6 +16,7 @@ git-permalink: src/git-permalink.sh.in check: all sh tests/cli-opts.sh sh tests/install-uninstall.sh + sh tests/remotes.sh dev-check: check sh aux/assert-shellcheck.sh diff --git a/tests/remotes.sh b/tests/remotes.sh new file mode 100755 index 0000000..27bb903 --- /dev/null +++ b/tests/remotes.sh @@ -0,0 +1,176 @@ +#!/bin/sh +set -u + +. aux/tests-lib.sh + +TEST_PREFIX="$PWD/tests/prefix/$(uuidgen)" +make PREFIX="$TEST_PREFIX" install 1>/dev/null +PATH="$PWD/tests:$TEST_PREFIX/bin:$PATH" + +new_repo() { + REPO="$PWD/tests/remotes/$(uuidgen)" + mkdir -p "$REPO" + pushd "$REPO" > /dev/null + git init > /dev/null + git remote add origin "$1" + echo '' > f.txt + git add f.txt + git commit -qam f.txt +} + +test_supported_remotes() { + testing 'supported remotes' + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo git://euandreh.xyz/remembering + LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_empty_stdout + assert_fgrep_stderr 'Opening https://git.euandreh.xyz' + assert_fgrep_stderr 'xdg-open: https://git.euandreh.xyz' + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://git.sr.ht/~sircmpwn/ctools + git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_fgrep_stdout 'https://git.sr.ht' + assert_empty_stderr + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://git.kernel.org/pub/scm/git/git.git + LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_empty_stdout + assert_fgrep_stderr 'Opening https://git.kernel.org' + assert_fgrep_stderr 'xdg-open: https://git.kernel.org' + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://git.savannah.gnu.org/guix.git + git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_fgrep_stdout 'https://git.savannah.gnu.org' + assert_empty_stderr + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://notabug.org/cwebber/guile-gcrypt + LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_empty_stdout + assert_fgrep_stderr 'Opening https://notabug.org' + assert_fgrep_stderr 'xdg-open: https://notabug.org' + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://codeberg.org/dnkl/yambar + git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_fgrep_stdout 'https://codeberg.org' + assert_empty_stderr + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://bitbucket.org/uprojects/jsmn + LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_empty_stdout + assert_fgrep_stderr 'Opening https://bitbucket.org' + assert_fgrep_stderr 'xdg-open: https://bitbucket.org' + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://pagure.io/aquedoc + git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_fgrep_stdout 'https://pagure.io' + assert_empty_stderr + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://gitlab.com/nonguix/nonguix + LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_empty_stdout + assert_fgrep_stderr 'Opening https://gitlab.com/nonguix/nonguix' + assert_fgrep_stderr 'xdg-open: https://gitlab.com/nonguix/nonguix' + popd > /dev/null + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://github.com/skeeto/elfeed + git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_fgrep_stdout 'https://github.com' + assert_empty_stderr + popd > /dev/null + + test_ok +} + +test_unsupported_remote() { + testing 'unsupported remotes' + + OUT="$(mktemp)" + ERR="$(mktemp)" + new_repo https://example.com/a/b + LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 1 + assert_empty_stdout + assert_fgrep_stderr 'Unsupported origin: https://example.com' + + OUT="$(mktemp)" + ERR="$(mktemp)" + git config git-permalink.template-commit-file 'before %s middle %s after' + git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_grep_stdout 'before .+ middle README.md after' + assert_empty_stderr + + OUT="$(mktemp)" + ERR="$(mktemp)" + git config --unset git-permalink.template-commit-file + git config git-permalink.template-file-commit 'before %s middle %s after' + git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_grep_stdout 'before README.md middle .+ after' + assert_empty_stderr + + OUT="$(mktemp)" + ERR="$(mktemp)" + git config --unset git-permalink.template-file-commit + LANG=POSIX git permalink -p README.md 123 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 1 + assert_empty_stdout + assert_fgrep_stderr 'Unsupported origin: https://example.com' + + test_ok +} + +test_supported_remotes +test_unsupported_remote |