Add installed package smoke tests in pkg-test directory

This commit is contained in:
Jay Berkenbilt 2022-03-17 21:06:23 -04:00 committed by Jay Berkenbilt
parent acdf5b2e7a
commit e316e90d1f
9 changed files with 139 additions and 1 deletions

View File

@ -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.

View File

@ -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
<https://wiki.debian.org/ContinuousIntegration/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

5
pkg-test/CMakeLists.txt Normal file
View File

@ -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)

14
pkg-test/README.md Normal file
View File

@ -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
```

7
pkg-test/qpdf-version.cc Normal file
View File

@ -0,0 +1,7 @@
#include <qpdf/QPDF.hh>
#include <iostream>
int main() {
std::cout << QPDF::QPDFVersion() << std::endl;
return 0;
}

34
pkg-test/run-all Executable file
View File

@ -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"

18
pkg-test/test-cli Executable file
View File

@ -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

18
pkg-test/test-cmake Executable file
View File

@ -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

21
pkg-test/test-pkg-config Executable file
View File

@ -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