diff --git a/README-maintainer b/README-maintainer index fd787e6b..3bac1549 100644 --- a/README-maintainer +++ b/README-maintainer @@ -326,6 +326,15 @@ rehash pip3 install . pytest -n auto +* Run package tests: + +cmake -S . -B build.tmp -DCMAKE_BUILD_TYPE=RelWithDebInfo +cmake --build build.tmp -j$(nproc) +DESTDIR=/tmp/inst cmake --install build.tmp +env PKG_CONFIG_PATH=/tmp/inst/usr/local/lib/pkgconfig \ + CMAKE_PREFIX_PATH=/tmp/inst/usr/local \ + ./pkg-test/run-all + CREATING A RELEASE @@ -339,7 +348,7 @@ CREATING A RELEASE version=x.y.z gpg --detach-sign --armor qpdf-$version.tar.gz -* Build and test the debian package +* Build and test the debian package. This includes running autopkgtest. * Add a calendar reminder to check the status of the debian package to make sure it is transitioning properly and to resolve any issues. diff --git a/manual/packaging.rst b/manual/packaging.rst index 50f8fc60..298a41a3 100644 --- a/manual/packaging.rst +++ b/manual/packaging.rst @@ -38,6 +38,18 @@ particularly useful to packagers. 11, this was a recommendation for packagers but was not done automatically. +.. _package-tests: + +Package Tests +------------- + +The :file:`pkg-test` directory contains very small test shell scripts +that are designed to help smoke-test an installation of qpdf. They +were designed to be used with debian's `autopkgtest +`__ +framework but can be used by others. Please see +:file:`pkg-test/README.md` in the source distribution for details. + .. _packaging-doc: Packaging Documentation diff --git a/pkg-test/CMakeLists.txt b/pkg-test/CMakeLists.txt new file mode 100644 index 00000000..36257f22 --- /dev/null +++ b/pkg-test/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.10) +project(qpdf-version LANGUAGES CXX) +find_package(qpdf) +add_executable(qpdf-version qpdf-version.cc) +target_link_libraries(qpdf-version qpdf::libqpdf) diff --git a/pkg-test/README.md b/pkg-test/README.md new file mode 100644 index 00000000..95f7ecb8 --- /dev/null +++ b/pkg-test/README.md @@ -0,0 +1,14 @@ +# Tests for installed packages + +The files in this directory are called by autopkgtest in the debian package but can be used by any packager to verify installed packages. Each test-* script should be run from the top of the source tree and takes an empty directory as its single argument. The test passes if the script exits with a zero exit status. Note that these tests write to stderr because they use set -x in the shell. + +On a GNU/Linux system, you can run `./pkg-test/run-all` from the top-level directory to run all the tests. For example: + +``` +cmake -S . -B build +cmake --build build -j$(nproc) +DESTDIR=/tmp/inst cmake --install build +env PKG_CONFIG_PATH=/tmp/inst/usr/local/lib/pkgconfig \ + CMAKE_PREFIX_PATH=/tmp/inst/usr/local \ + ./pkg-test/run-all +``` diff --git a/pkg-test/qpdf-version.cc b/pkg-test/qpdf-version.cc new file mode 100644 index 00000000..63fd3308 --- /dev/null +++ b/pkg-test/qpdf-version.cc @@ -0,0 +1,7 @@ +#include +#include + +int main() { + std::cout << QPDF::QPDFVersion() << std::endl; + return 0; +} diff --git a/pkg-test/run-all b/pkg-test/run-all new file mode 100755 index 00000000..e68044d6 --- /dev/null +++ b/pkg-test/run-all @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -e + +cd $(dirname $0)/.. + +CUR_TEMP= +function clean_temp() { + if [[ $CUR_TEMP =~ .*\.qpdf-test$ && -d $CUR_TEMP ]]; then + rm -rf $CUR_TEMP + fi +} + +trap clean_temp EXIT + +declare -a any_failed +for i in pkg-test/test-*; do + if [[ $i =~ .*~ ]]; then + continue + fi + CUR_TEMP=$(mktemp --suffix=.qpdf-test -d) + printf "\n\n\e[40m\e[1;35m*** RUNNING $i ***\e[0m\n\n\n" + if ! $i $CUR_TEMP; then + any_failed=(${any_failed[*]} $i) + fi + clean_temp +done + +if [[ ${#any_failed} != 0 ]]; then + for i in ${any_failed[*]}; do + echo 1>&2 "FAILED: $i" + done + exit 2 +fi +printf "\n\n\e[40m\e[1;35m*** ALL TESTS PASSED ***\e[0m\n" diff --git a/pkg-test/test-cli b/pkg-test/test-cli new file mode 100755 index 00000000..6b1c1d88 --- /dev/null +++ b/pkg-test/test-cli @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Test that the installed qpdf CLI works. Requires the CLI and runtime +# libraries. +# +set -ex + +TMP=$1 +if [ ! -d "$TMP" ]; then + echo 1>&2 "Usage: $0 tmp-dir" + exit 2 +fi + +qpdf --version +qpdf --help +qpdf --check qpdf/qtest/qpdf/minimal.pdf +qpdf qpdf/qtest/qpdf/minimal.pdf --encrypt u o 256 -- $TMP/out.pdf +qpdf --check --password=u $TMP/out.pdf diff --git a/pkg-test/test-cmake b/pkg-test/test-cmake new file mode 100755 index 00000000..4fd5846b --- /dev/null +++ b/pkg-test/test-cmake @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Test that the installed qpdf development packages enable a qpdf +# application to be build with information from pkg-config. Requires +# pkg-config as well as libqpdf development dependencies. +# +set -ex + +TMP=$1 +if [ ! -d "$TMP" ]; then + echo 1>&2 "Usage: $0 tmp-dir" + exit 2 +fi +cp pkg-test/qpdf-version.cc pkg-test/CMakeLists.txt $TMP +cd $TMP +cmake -S . -B build +cmake --build build +./build/qpdf-version diff --git a/pkg-test/test-pkg-config b/pkg-test/test-pkg-config new file mode 100755 index 00000000..c516bed6 --- /dev/null +++ b/pkg-test/test-pkg-config @@ -0,0 +1,21 @@ +#!/bin/sh +# +# Test that the installed qpdf development packages enable a qpdf +# application to be build with cmake using qpdf's cmake package +# information. Requires cmake as well as libqpdf development +# dependencies. +# +set -ex + +TMP=$1 +if [ ! -d "$TMP" ]; then + echo 1>&2 "Usage: $0 tmp-dir" + exit 2 +fi + +cp pkg-test/qpdf-version.cc $TMP +cd $TMP +g++ qpdf-version.cc -o qpdf-version \ + $(pkg-config libqpdf --cflags) \ + $(pkg-config libqpdf --libs) +./qpdf-version