summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-07-08 23:25:50 +0200
committerAki <please@ignore.pl>2022-07-08 23:25:50 +0200
commit9e041568f6269e259009efc3fb147a7e679e5153 (patch)
tree52092037eabc0b27add79f125084fbd87492f0c4
parent44f8afdc44d4d7dd0124fac984356c18b966f2db (diff)
downloadpkgrel-9e041568f6269e259009efc3fb147a7e679e5153.zip
pkgrel-9e041568f6269e259009efc3fb147a7e679e5153.tar.gz
pkgrel-9e041568f6269e259009efc3fb147a7e679e5153.tar.bz2
Implemented naive tests for common cases
-rw-r--r--Makefile5
-rwxr-xr-xtest.sh115
2 files changed, 119 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index d877394..4fc93e6 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..28d33f7
--- /dev/null
+++ b/test.sh
@@ -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