diff options
-rw-r--r-- | Makefile | 5 | ||||
-rwxr-xr-x | test.sh | 115 |
2 files changed, 119 insertions, 1 deletions
@@ -23,4 +23,7 @@ uninstall: rm -f $(DESTDIR)$(BINDIR)/pkgrel rm -f $(DESTDIR)$(MANDIR)/pkgrel.1 -.PHONY: all clean install uninstall +test: pkgrel + @./test.sh 2>/dev/null + +.PHONY: all clean install uninstall test @@ -0,0 +1,115 @@ +#!/bin/sh +test_increments() { + local pkgrel="$1" + local repo="$2" + cd "$repo" + git init + cat >PKGBUILD <<-PKGBUILD_initial + # Maintainer: Test <test@acme.com> + pkgname=test + pkgver=1.0.0 + pkgdesc="Package intended for testing" + PKGBUILD_initial + git add PKGBUILD + git commit -m "Initial commit" + test "$($pkgrel)" -eq 1 || exit 1 + echo >>PKGBUILD "arch=(i686 x86_64)" + test "$($pkgrel)" -eq 2 || exit 1 + git commit -am "Added architecture" + test "$($pkgrel)" -eq 2 || exit 1 + sed -i "s/1.0.0/1.1.0/" PKGBUILD + git commit -am "Bumped version" + test "$($pkgrel)" -eq 1 || exit 1 + sed -i "s/intended/created/" PKGBUILD + test "$($pkgrel)" -eq 2 || exit 1 + sed -i "s/testing/rolling/" PKGBUILD + test "$($pkgrel)" -eq 2 || exit 1 + git commit -am "Updated purpose of package" + test "$($pkgrel)" -eq 2 || exit 1 + sed -i "s/Package/Distribution/" PKGBUILD + test "$($pkgrel)" -eq 3 || exit 1 +} + + +test_root() { + local pkgrel="$1" + local repo="$2" + cd "$repo" + $pkgrel && exit 1 + git init + $pkgrel && exit 1 + touch hello + git add hello + git commit -m "Initial commit" + $pkgrel && exit 1 + touch PKGBUILD + test "$($pkgrel)" -eq 1 || exit 1 + git add PKGBUILD + git commit -m "Added PKGBUILD" + test "$($pkgrel)" -eq 1 || exit 1 + echo >>PKGBUILD "pkgname=test" + test "$($pkgrel)" -eq 2 || exit 1 + echo >>PKGBUILD "pkgver=1.0.0" + test "$($pkgrel)" -eq 1 || exit 1 + git commit -am "Added version and name to package" + test "$($pkgrel)" -eq 1 || exit 1 +} + + +test_nested() { + local pkgrel="$1" + local repo="$2" + cd "$repo" + git init + mkdir -p first second/sub + touch first/PKGBUILD second/PKGBUILD second/sub/PKGBUILD + git add first/PKGBUILD second/PKGBUILD second/sub/PKGBUILD + git commit -m "Initial commit" + $pkgrel && exit 1 + cd "$repo/first" + test "$($pkgrel)" -eq 1 || exit 1 + cd "$repo/second" + test "$($pkgrel)" -eq 1 || exit 1 + cd "$repo/second/sub" + test "$($pkgrel)" -eq 1 || exit 1 + echo >>PKGBUILD "pkgname=sub" + test "$($pkgrel)" -eq 2 || exit 1 + cd "$repo/second" + test "$($pkgrel)" -eq 1 || exit 1 + echo >>PKGBUILD "pkgname=second" + test "$($pkgrel)" -eq 2 || exit 1 + cd "$repo/first" + test "$($pkgrel)" -eq 1 || exit 1 + git commit -am "Added names to second and sub" + test "$($pkgrel)" -eq 1 || exit 1 + cd "$repo/second" + test "$($pkgrel)" -eq 2 || exit 1 + echo >>PKGBUILD "pkgver=1.0.0" + test "$($pkgrel)" -eq 1 || exit 1 + cd "$repo/second/sub" + test "$($pkgrel)" -eq 2 || exit 1 + git commit -am "Added version to second" + test "$($pkgrel)" -eq 2 || exit 1 +} + + +ok() { + echo -e "${1:-unknown}... \033[32;1mok\033[0m" +} + + +fail() { + echo -e "${1:-unknown}... \033[31;1mfail\033[0m" +} + + +execute_test() { + local test_name="$1" + repo=$(mktemp -d) + ( $test_name "$PWD/pkgrel" "$repo" ) 1>&2 && ok "$test_name" || fail "$test_name" + rm -rf "$repo" +} + +execute_test test_increments +execute_test test_root +execute_test test_nested |