Add test case for scriptlet behavior
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 21 Mar 2012 08:04:14 +0000 (10:04 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 21 Mar 2012 08:10:07 +0000 (10:10 +0200)
- The test-root has a shell but rpm doesn't know about it, add a
  fakeshell metapackage that provides it. Should come in handy for
  other cases as well, up to now we've been limited to lua scripts only.
- Test that all the "normal" scripts get executed, in expected order
  and with expected arguments, on install, upgrade and erase.
- This would've saved the rather embarrassing breakage with commit
  274dbf557d1cac90f7c278f9b6d6af05997d92df at least, but better
  late than never as they say... It also serves to highlight and
  document  the arguably broken arguments to %pre- and %posttrans
  scripts (ie always 0)

tests/Makefile.am
tests/data/SPECS/fakeshell.spec [new file with mode: 0644]
tests/data/SPECS/scripts.spec [new file with mode: 0644]
tests/rpmscript.at [new file with mode: 0644]
tests/rpmtests.at

index 72b17ca..ff7e498 100644 (file)
@@ -27,6 +27,7 @@ TESTSUITE_AT += rpmconfig.at
 TESTSUITE_AT += rpmmacro.at
 TESTSUITE_AT += rpmpython.at
 TESTSUITE_AT += rpmdepmatch.at
+TESTSUITE_AT += rpmscript.at
 EXTRA_DIST += $(TESTSUITE_AT)
 
 ## testsuite data
@@ -42,6 +43,8 @@ EXTRA_DIST += data/SPECS/hlinktest.spec
 EXTRA_DIST += data/SPECS/symlinktest.spec
 EXTRA_DIST += data/SPECS/deptest.spec
 EXTRA_DIST += data/SPECS/verifyscript.spec
+EXTRA_DIST += data/SPECS/fakeshell.spec
+EXTRA_DIST += data/SPECS/scripts.spec
 EXTRA_DIST += data/SOURCES/hello-1.0-modernize.patch
 EXTRA_DIST += data/SOURCES/hello-1.0.tar.gz
 EXTRA_DIST += data/SOURCES/hello-2.0.tar.gz
diff --git a/tests/data/SPECS/fakeshell.spec b/tests/data/SPECS/fakeshell.spec
new file mode 100644 (file)
index 0000000..88b5fe1
--- /dev/null
@@ -0,0 +1,12 @@
+Name: fakeshell
+Version: 1.0
+Release: 1
+Summary: Fake provides for shell
+License: GPL
+BuildArch: noarch
+Provides: /bin/sh
+
+%description
+%{summary}
+
+%files
diff --git a/tests/data/SPECS/scripts.spec b/tests/data/SPECS/scripts.spec
new file mode 100644 (file)
index 0000000..fbb9bc9
--- /dev/null
@@ -0,0 +1,31 @@
+Name:           scripts
+Version:        1.0
+Release:        %{rel}
+Summary:        Testing script behavior
+Group:          Testing
+License:        GPL
+BuildArch:     noarch
+
+%description
+%{summary}
+
+%files
+%defattr(-,root,root,-)
+
+%pretrans
+echo %{name}-%{version}-%{release} PRETRANS $*
+
+%pre
+echo %{name}-%{version}-%{release} PRE $*
+
+%post
+echo %{name}-%{version}-%{release} POST $*
+
+%preun
+echo %{name}-%{version}-%{release} PREUN $*
+
+%postun
+echo %{name}-%{version}-%{release} POSTUN $*
+
+%posttrans
+echo %{name}-%{version}-%{release} POSTTRANS $*
diff --git a/tests/rpmscript.at b/tests/rpmscript.at
new file mode 100644 (file)
index 0000000..ab44785
--- /dev/null
@@ -0,0 +1,39 @@
+#    rpmscript.at: rpm scriptlet tests
+
+AT_BANNER([RPM scriptlets])
+
+# ------------------------------
+# 
+AT_SETUP([basic scripts and arguments])
+AT_KEYWORDS([verify])
+AT_CHECK([
+RPMDB_CLEAR
+RPMDB_INIT
+rm -rf "${TOPDIR}"
+
+runroot rpmbuild --quiet -bb /data/SPECS/fakeshell.spec
+runroot rpmbuild --quiet -bb --define "rel 1" /data/SPECS/scripts.spec
+runroot rpmbuild --quiet -bb --define "rel 2" /data/SPECS/scripts.spec
+
+runroot rpm -U "${TOPDIR}"/RPMS/noarch/fakeshell-1.0-1.noarch.rpm
+runroot rpm -U "${TOPDIR}"/RPMS/noarch/scripts-1.0-1.noarch.rpm
+runroot rpm -U "${TOPDIR}"/RPMS/noarch/scripts-1.0-2.noarch.rpm
+runroot rpm -e scripts
+],
+[0],
+[scripts-1.0-1 PRETRANS 0
+scripts-1.0-1 PRE 1
+scripts-1.0-1 POST 1
+scripts-1.0-1 POSTTRANS 0
+scripts-1.0-2 PRETRANS 0
+scripts-1.0-2 PRE 2
+scripts-1.0-2 POST 2
+scripts-1.0-1 PREUN 1
+scripts-1.0-1 POSTUN 1
+scripts-1.0-2 POSTTRANS 0
+scripts-1.0-2 PREUN 0
+scripts-1.0-2 POSTUN 0
+],
+[])
+AT_CLEANUP
+
index 7f0807d..c1ea9c3 100644 (file)
@@ -4,6 +4,7 @@ m4_include([rpmverify.at])
 m4_include([rpmdb.at])
 m4_include([rpmi.at])
 m4_include([rpmbuild.at])
+m4_include([rpmscript.at])
 m4_include([rpmvercmp.at])
 m4_include([rpmdeps.at])
 m4_include([rpmconflict.at])