Commit e316e90d1f3124e1ddb7f33f77b91af178b963bd

Authored by Jay Berkenbilt
Committed by Jay Berkenbilt
1 parent acdf5b2e

Add installed package smoke tests in pkg-test directory

README-maintainer
@@ -326,6 +326,15 @@ rehash @@ -326,6 +326,15 @@ rehash
326 pip3 install . 326 pip3 install .
327 pytest -n auto 327 pytest -n auto
328 328
  329 +* Run package tests:
  330 +
  331 +cmake -S . -B build.tmp -DCMAKE_BUILD_TYPE=RelWithDebInfo
  332 +cmake --build build.tmp -j$(nproc)
  333 +DESTDIR=/tmp/inst cmake --install build.tmp
  334 +env PKG_CONFIG_PATH=/tmp/inst/usr/local/lib/pkgconfig \
  335 + CMAKE_PREFIX_PATH=/tmp/inst/usr/local \
  336 + ./pkg-test/run-all
  337 +
329 338
330 CREATING A RELEASE 339 CREATING A RELEASE
331 340
@@ -339,7 +348,7 @@ CREATING A RELEASE @@ -339,7 +348,7 @@ CREATING A RELEASE
339 version=x.y.z 348 version=x.y.z
340 gpg --detach-sign --armor qpdf-$version.tar.gz 349 gpg --detach-sign --armor qpdf-$version.tar.gz
341 350
342 -* Build and test the debian package 351 +* Build and test the debian package. This includes running autopkgtest.
343 352
344 * Add a calendar reminder to check the status of the debian package to 353 * Add a calendar reminder to check the status of the debian package to
345 make sure it is transitioning properly and to resolve any issues. 354 make sure it is transitioning properly and to resolve any issues.
manual/packaging.rst
@@ -38,6 +38,18 @@ particularly useful to packagers. @@ -38,6 +38,18 @@ particularly useful to packagers.
38 11, this was a recommendation for packagers but was not done 38 11, this was a recommendation for packagers but was not done
39 automatically. 39 automatically.
40 40
  41 +.. _package-tests:
  42 +
  43 +Package Tests
  44 +-------------
  45 +
  46 +The :file:`pkg-test` directory contains very small test shell scripts
  47 +that are designed to help smoke-test an installation of qpdf. They
  48 +were designed to be used with debian's `autopkgtest
  49 +<https://wiki.debian.org/ContinuousIntegration/autopkgtest>`__
  50 +framework but can be used by others. Please see
  51 +:file:`pkg-test/README.md` in the source distribution for details.
  52 +
41 .. _packaging-doc: 53 .. _packaging-doc:
42 54
43 Packaging Documentation 55 Packaging Documentation
pkg-test/CMakeLists.txt 0 → 100644
  1 +cmake_minimum_required(VERSION 3.10)
  2 +project(qpdf-version LANGUAGES CXX)
  3 +find_package(qpdf)
  4 +add_executable(qpdf-version qpdf-version.cc)
  5 +target_link_libraries(qpdf-version qpdf::libqpdf)
pkg-test/README.md 0 → 100644
  1 +# Tests for installed packages
  2 +
  3 +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.
  4 +
  5 +On a GNU/Linux system, you can run `./pkg-test/run-all` from the top-level directory to run all the tests. For example:
  6 +
  7 +```
  8 +cmake -S . -B build
  9 +cmake --build build -j$(nproc)
  10 +DESTDIR=/tmp/inst cmake --install build
  11 +env PKG_CONFIG_PATH=/tmp/inst/usr/local/lib/pkgconfig \
  12 + CMAKE_PREFIX_PATH=/tmp/inst/usr/local \
  13 + ./pkg-test/run-all
  14 +```
pkg-test/qpdf-version.cc 0 → 100644
  1 +#include <qpdf/QPDF.hh>
  2 +#include <iostream>
  3 +
  4 +int main() {
  5 + std::cout << QPDF::QPDFVersion() << std::endl;
  6 + return 0;
  7 +}
pkg-test/run-all 0 → 100755
  1 +#!/usr/bin/env bash
  2 +set -e
  3 +
  4 +cd $(dirname $0)/..
  5 +
  6 +CUR_TEMP=
  7 +function clean_temp() {
  8 + if [[ $CUR_TEMP =~ .*\.qpdf-test$ && -d $CUR_TEMP ]]; then
  9 + rm -rf $CUR_TEMP
  10 + fi
  11 +}
  12 +
  13 +trap clean_temp EXIT
  14 +
  15 +declare -a any_failed
  16 +for i in pkg-test/test-*; do
  17 + if [[ $i =~ .*~ ]]; then
  18 + continue
  19 + fi
  20 + CUR_TEMP=$(mktemp --suffix=.qpdf-test -d)
  21 + printf "\n\n\e[40m\e[1;35m*** RUNNING $i ***\e[0m\n\n\n"
  22 + if ! $i $CUR_TEMP; then
  23 + any_failed=(${any_failed[*]} $i)
  24 + fi
  25 + clean_temp
  26 +done
  27 +
  28 +if [[ ${#any_failed} != 0 ]]; then
  29 + for i in ${any_failed[*]}; do
  30 + echo 1>&2 "FAILED: $i"
  31 + done
  32 + exit 2
  33 +fi
  34 +printf "\n\n\e[40m\e[1;35m*** ALL TESTS PASSED ***\e[0m\n"
pkg-test/test-cli 0 → 100755
  1 +#!/bin/sh
  2 +#
  3 +# Test that the installed qpdf CLI works. Requires the CLI and runtime
  4 +# libraries.
  5 +#
  6 +set -ex
  7 +
  8 +TMP=$1
  9 +if [ ! -d "$TMP" ]; then
  10 + echo 1>&2 "Usage: $0 tmp-dir"
  11 + exit 2
  12 +fi
  13 +
  14 +qpdf --version
  15 +qpdf --help
  16 +qpdf --check qpdf/qtest/qpdf/minimal.pdf
  17 +qpdf qpdf/qtest/qpdf/minimal.pdf --encrypt u o 256 -- $TMP/out.pdf
  18 +qpdf --check --password=u $TMP/out.pdf
pkg-test/test-cmake 0 → 100755
  1 +#!/bin/sh
  2 +#
  3 +# Test that the installed qpdf development packages enable a qpdf
  4 +# application to be build with information from pkg-config. Requires
  5 +# pkg-config as well as libqpdf development dependencies.
  6 +#
  7 +set -ex
  8 +
  9 +TMP=$1
  10 +if [ ! -d "$TMP" ]; then
  11 + echo 1>&2 "Usage: $0 tmp-dir"
  12 + exit 2
  13 +fi
  14 +cp pkg-test/qpdf-version.cc pkg-test/CMakeLists.txt $TMP
  15 +cd $TMP
  16 +cmake -S . -B build
  17 +cmake --build build
  18 +./build/qpdf-version
pkg-test/test-pkg-config 0 → 100755
  1 +#!/bin/sh
  2 +#
  3 +# Test that the installed qpdf development packages enable a qpdf
  4 +# application to be build with cmake using qpdf's cmake package
  5 +# information. Requires cmake as well as libqpdf development
  6 +# dependencies.
  7 +#
  8 +set -ex
  9 +
  10 +TMP=$1
  11 +if [ ! -d "$TMP" ]; then
  12 + echo 1>&2 "Usage: $0 tmp-dir"
  13 + exit 2
  14 +fi
  15 +
  16 +cp pkg-test/qpdf-version.cc $TMP
  17 +cd $TMP
  18 +g++ qpdf-version.cc -o qpdf-version \
  19 + $(pkg-config libqpdf --cflags) \
  20 + $(pkg-config libqpdf --libs)
  21 +./qpdf-version