.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Lintian::Tutorial::WritingTests 3" .TH Lintian::Tutorial::WritingTests 3 "2021-02-01" "Lintian v2.104.0~bpo10+1" "Debian Package Checker" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Lintian::Tutorial::WritingTests \-\- Short tutorial on writing tests .SH "SYNOPSIS" .IX Header "SYNOPSIS" Warning: This document may be out of date. .PP This document attempts to be a short / quick tutorial to the Lintian test suite from a test-writer's perspective. As such, it will only cover the standard type of tests (from the \*(L"tests\*(R" suite). .PP The guide will involve writing a test for the \*(L"deb/pkg\-check\*(R" check, which was documented in the Lintian::Tutorial::WritingChecks tutorial. .PP For running tests, please see Lintian::Tutorial::TestSuite instead. .SH "DESCRIPTION" .IX Header "DESCRIPTION" The Lintian test suite is divided into several parts. These are: .IP "\-" 4 scripts .Sp Small (Perl) \*(L"prove\*(R" tests. These assert that code style, data files and/or self-contained code units (i.e. unit tests) work as intended. They are \fBnot\fR used for testing Lintian tags. .IP "\-" 4 tags .Sp These tests all test for the presence of tags after building test packages using skeletons. For most cases, we recommend .Sp .Vb 1 \& Skeleton: upload\-non\-native .Ve .Sp suites are small test suites that test some particular tags for \&\fI.changes\fR, \fI.deb\fR or \fI.dsc\fR files. Typically, you will find the more exotic tags here, which require some special fiddling and cannot be built by a \*(L"standard\*(R" dh7 + dpkg build. .IP "\-" 4 literal .Sp These tests look to match the literal output of Lintian. These tests are useful as general false positives. They also catch Lintian messages unrelated to tags. .PP With this in mind, let us move on to the scope. .SS "Scope of the tutorial" .IX Subsection "Scope of the tutorial" \&\s-1WARNING: THE REMAINDER OF THIS TUTORIAL IS OUT OF DATE.\s0 .PP The \*(L"tests\*(R" suite alone is fairly complex on its own. To keep things simple, the tutorial will limit itself to creating a \*(L"native\*(R" package with no special requirements in the \*(L"tests\*(R" suite. .PP In particular, note that the tags \fImust not\fR be \fIpedantic\fR for this to work. If you followed the check writing tutorial and made the tags pedantic, please change them into \*(L"I\*(R", \*(L"W\*(R" or \*(L"E\*(R" tags. .PP Once the basics are covered, you should be better equipped to deal with the other (\*(L"tag testing\*(R") suites or using other features of the \&\*(L"tests\*(R" suite (e.g. pedantic tags). .SS "The design of the Lintian test suite" .IX Subsection "The design of the Lintian test suite" The basic design of the Lintian test suite can be summed up as \fIless is more\fR. The Debian build system is changing all the time (albeit, slowly) and sometimes it deprecates or breaks existing features. .PP With over 400 tests all featuring the same basic parts, the test suite features several tricks to keep up with the pace. It uses \*(L"skeletons\*(R" (template) directories to seed the package structures and template files to fill in the basic files (e.g. \*(L"debian/control\*(R" and \&\*(L"debian/changelog\*(R"). .PP This means that when a new standards-version comes along, debhelper deprecates a feature or (more likely) Lintian adds a new tag, the majority of the tests can quickly be adapted with only a minor effort. .PP Since pedantic tags tend to require additional effort to avoid, most Lintian tests do \fBnot\fR run with pedantic tags enabled. .ie n .SS "The basics of a ""native"" package in the ""tests"" suite" .el .SS "The basics of a ``native'' package in the ``tests'' suite" .IX Subsection "The basics of a native package in the tests suite" For starters, you need 2 files and 1 directory, which will be placed in \fIt/tests/\fR. .PP \fIThe desc file (mandatory)\fR .IX Subsection "The desc file (mandatory)" .PP This is the test description file. It is a deb822 file (i.e. same syntax as \fIdebian/control\fR), which contains a number of fields. .PP Let's start with the following template: .PP .Vb 6 \& Testname: pkg\-deb\-check\-general \& Version: 1.0 \& Description: General test of the pkg/deb\-check check \& Test\-For: \& missing\-multi\-arch\-field \& missing\-pre\-depends\-on\-multiarch\-support .Ve .PP This defines the name of the test, its sequence number (i.e. how early it should be run), the version of the \fIgenerated\fR package, a description and the tags you intend to test for. .PP In case you were wondering why \*(L"invalid-multi-arch-field\*(R" is not listed, then it is because dpkg will not allow us to use an invalid Multi-Arch value. Therefore, that particular tag would have to be tested in the \*(L"debs\*(R" suite instead. .PP Note that the value of the Testname field (as Source field), Version field and Description field (as the synopsis) \fIwill\fR be used in the package. As such, they must obey the normal requirements for these purposes. .PP Please keep the following conventions in mind: .IP "\-" 4 The Testname should be \*(L"\-\*(R" .Sp Note that regular Lintian checks do \fInot\fR have a \*(L"/\*(R", so the naming convention works slightly better there. .IP "\-" 4 The Version should always be \*(L"1.0\*(R" unless the test requires anything else. .Sp For non-native packages, the default would be \*(L"1.0\-1\*(R". .PP \fIThe \*(L"tags\*(R" file (mandatory, but may be empty)\fR .IX Subsection "The tags file (mandatory, but may be empty)" .PP This file contains the \fIsorted\fR \*(L"expected\*(R" output of lintian. Assuming all of the tags are \*(L"I\*(R" tags, the file should look something like: .PP .Vb 2 \& I: pkg\-deb\-check\-general\-missing\-ma: missing\-multi\-arch\-field \& I: pkg\-deb\-check\-general\-missing\-pred: missing\-pre\-depends\-on\-multiarch\-support .Ve .PP \fIThe \*(L"debian/\*(R" directory (optional, but usually needed)\fR .IX Subsection "The debian/ directory (optional, but usually needed)" .PP The unpacked debian package in its full glory. Note that this means that the (e.g.) \fIdebian/rules\fR file would be \fIt/tests//debian/debian/rules\fR (note the double \&\*(L"debian/\*(R"). .PP The directory is seeded from \fIt/templates/tests//\fR, where \fIskeleton\fR is the value of the \*(L"Skeleton\*(R" field from the \*(L"desc\*(R" file. .PP For this test, you only need a specialized control file. This file could look something like: .PP .Vb 6 \& Source: {$source} \& Priority: extra \& Section: {$section} \& Maintainer: {$author} \& Standards\-Version: {$standards_version} \& Build\-Depends: {$build_depends} \& \& Package: {$source}\-missing\-ma \& Architecture: {$architecture} \& Depends: $\e{shlibs:Depends\e}, $\e{misc:Depends\e} \& Description: {$description} (invalid) \& This is a test package designed to exercise some feature or tag of \& Lintian. It is part of the Lintian test suite and may do very odd \& things. It should not be installed like a regular package. It may \& be an empty package. \& . \& Missing M\-A field. \& \& Package: {$source}\-missing\-pred \& Architecture: any \& Depends: $\e{shlibs:Depends\e}, $\e{misc:Depends\e} \& Multi\-arch: same \& Description: {$description} (pre\-depends) \& This is a test package designed to exercise some feature or tag of \& Lintian. It is part of the Lintian test suite and may do very odd \& things. It should not be installed like a regular package. It may \& be an empty package. \& . \& Missing Pre\-Depends. .Ve .PP \fIRunning the test\fR .IX Subsection "Running the test" .PP At this point, the test is in fact ready to be executed. It can be run by using: .PP .Vb 1 \& $ debian/rules runtests onlyrun=pkg\-deb\-check\-general \& \& OR \& \& $ private/runtests \-\-dump\-logs t debian/test\-out pkg\-deb\-check\-general .Ve .PP However, it will not emit the correct tags unless pkg/deb\-check is part of the debian/main lintian profile. If your check is a part of a different profile, add the \*(L"Profile: \*(R" field to the \*(L"desc\*(R" file. .PP With this, the tutorial is over. Below you will find some more resources that may be useful to your future test writing work. .SH "REFERENCES / APPENDIX" .IX Header "REFERENCES / APPENDIX" .SS "A step-by-step guide of how a test case works" .IX Subsection "A step-by-step guide of how a test case works" Basically, the tag-testing test cases all involve building a package and running lintian on the result. The \*(L"tests\*(R" suite does a full build with dpkg-buildpackage, the other suites \*(L"hand-craft\*(R" only the type of artifacts they are named after (e.g. \*(L"source\*(R" produces only source packages). .PP \fIA test in the \*(L"tests\*(R" suite\fR .IX Subsection "A test in the tests suite" .PP The basic process of a lintian test in the \*(L"tests\*(R" suite. .IP "1." 4 Copy the \*(L"upstream\*(R" skeleton dir into the build dir (non-native only) .IP "2." 4 Copy the \*(L"upstream\*(R" dir from the test into the build dir (if present, non-native only) .IP "3." 4 Run the \*(L"pre_upstream\*(R" hook (if present, non-native only) .IP "4." 4 Assemble the upstream tarball (non-native only) .IP "5." 4 Copy the \*(L"debian\*(R" skeleton dir into the build dir .IP "6." 4 Copy the \*(L"debian\*(R" directory from the test into the build dir (if present) .IP "7." 4 Create debian/control and debian/changelog from "\fI\fR.in" if they do not exist. .IP "8." 4 Create an empty watch file (if missing, non-native only) .IP "9." 4 Run the \*(L"pre_build\*(R" hook (if present) .IP "10." 4 Run dpkg-buildpackage .IP "11." 4 Run lintian on the build result .IP "12." 4 Run the \*(L"post_test\*(R" hook (if present) .IP "13." 4 Run the \*(L"test_calibration\*(R" hook (if present), which may produce a new \*(L"expected output file\*(R". .IP "14." 4 Compare the result with the expected output. .PP Note that the majority of the steps are conditional on native/non\-native packages or presence of hooks. .PP \fIA test in the \*(L"debs\*(R" and the \*(L"source\*(R" suite\fR .IX Subsection "A test in the debs and the source suite" .PP The \*(L"debs\*(R" and the \*(L"source\*(R" suite share the same basic steps, which are: .IP "1." 4 Copy the skeleton dir into the build dir .IP "2." 4 Copy the test directory files into the build dir .IP "3." 4 Create changelog, control, and (debs-only) Makefile from "\fI\fR.in" if they do not exist. .IP "4." 4 Run make in the build dir .IP "5." 4 Run lintian on the produced artifact (there must be exactly one) .IP "6." 4 Compare the result with the expected output. .PP \fIA test in the \*(L"changes\*(R" suite\fR .IX Subsection "A test in the changes suite" .PP The changes test is fairly simple as there is not much building. The steps are as the following: .IP "1." 4 Find or compute the test artifact as the following: .RS 4 .IP "\-" 4 If \fI/.changes\fR exists, it is used as the artifact. .IP "\-" 4 Otherwise, copy \fI/.changes.in\fR into the build dir and use it as a template to create \fI/.changes\fR. The result is then used as the artifact to test. .RE .RS 4 .RE .IP "2." 4 Run lintian run on the artifact .IP "3." 4 Compare the result with the expected output .ie n .SS "The full layout of a test in the ""tests"" suite" .el .SS "The full layout of a test in the ``tests'' suite" .IX Subsection "The full layout of a test in the tests suite" Each test in the \*(L"tests\*(R" suite is placed in \&\fIt/tests/\-\fR. In these you will find some of the following files: .IP "\-" 4 desc (mandatory) .Sp This is the test description file. It is a deb822 file (i.e. same syntax as \fIdebian/control\fR), which contains a number of fields. .IP "\-" 4 tags (mandatory, but may be empty) .Sp This file contains the \*(L"expected\*(R" output of lintian. .Sp This is generally sorted, though a few tests rely on the order of the output. This can be controlled via the \*(L"Sort\*(R" field in the \*(L"desc\*(R" file. .IP "\-" 4 debian/ (optional, but usually what you need) .Sp The unpacked debian package. For \*(L"native\*(R" package tests, this is \&\fIalso\fR the \*(L"upstream\*(R" part. For \*(L"non-native\*(R" package tests, this can be used to override files in the \*(L"upstream\*(R" part (rarely needed). .Sp The actual packaging files (e.g. \fIdebian/rules\fR) would be in .Sp .Vb 1 \& I<< t/tests//debian/debian/rules >> .Ve .Sp Note the double \*(L"debian\*(R". .Sp This part is seeded from \fIt/templates/tests//\fR, where \fIskeleton\fR is the value of the \*(L"Skeleton\*(R" field from the \*(L"desc\*(R" file. .IP "\-" 4 upstream/ (optional, rarely needed) .Sp This directory is the used to create the \*(L"upstream\*(R" tarball for \&\*(L"non-native\*(R" package tests. Since most tags are emitted for both \&\*(L"native\*(R" and \*(L"non-native\*(R" tests, it is simpler (and slightly faster) to use \*(L"native\*(R" packages for most tests. .Sp The files here should also be present with the same contents in the debian directory unless you're intentionally creating a diff. However, as normal with a Debian package, you can omit files entirely from the debian directory and the deletions will be ignored by dpkg-buildpackage. .Sp The directory will be seeded from \fIt/templates/tests/.upstream/\fR, where \fIskeleton\fR is the value of the \*(L"Skeleton\*(R" field from the \*(L"desc\*(R" file. .IP "\-" 4 post_test (optional, rarely needed) .Sp This script (if present) is a sed script that can be used to \*(L"massage\*(R" the output of lintian before comparing it with the \*(L"expected output\*(R". .Sp The most common use for this script is to remove the architecture name, multi-arch path, drop hardening tags or exact standards-version number from tags output. Here are some examples files used: .Sp .Vb 3 \& # Remove the exact standards version, so the tags file will not need \& # to be updated with every new standards\-version \& s/\e(current is ([0\-9]+\e.)+[0\-9]\e)/(current is CURRENT)/ \& \& # Drop all hardening tags (they can differ between architectures) \& /: hardening\-.*/ d \& \& # Massage e.g. usr/lib/i386\-linux\-gnu/pkgconfig into a generic path \& s, usr/lib/[^/]+/pkgconfig/, usr/lib/ARCH/pkgconfig/, .Ve .Sp It may be useful for other cases where the output of Lintian may change on different systems. .IP "\-" 4 pre_build / pre_upstream (optional, special case usage) .Sp If present and executable, these scripts can be used to mess with the package directory and (what will become) the upstream tarball. .Sp Their common use case is to create files in the tarballs that cannot (or preferably should not) be included in the revision control system. Common cases include \*(L"binary\*(R", \*(L"minimized\*(R" files or files with \*(L"weird\*(R" names such as backslashes or non \s-1UTF\-8\s0 characters. .Sp Both scripts receive a directory as first argument, which is the directory they should work on. For: .RS 4 .IP "\-" 4 pre_upstream .Sp The script will be run before the upstream tarball is compiled. The first argument is the directory that will be included in the upstream tarball. .IP "\-" 4 pre_build .Sp The script will be run before dpkg-buildpackage is invoked. The first argument is the directory of the unpacked debian source package. .RE .RS 4 .RE .IP "\-" 4 test_calibration (optional, special case usage) .Sp If present and executable, this script will be invoked \fBafter\fR lintian \fIand\fR post_test (if present) have been run. The script can then modify the expected output \fIand\fR the actual output. .Sp This is useful for those extremely rare cases where post_test is insufficient to handle the requirements. So far, this has only been needed for the hardening checks, where the output differs between architectures. .Sp The script will be passed 3 arguments: .RS 4 .IP "\-" 4 Path to the \*(L"expected output\*(R" file (read-only) .Sp This is the \*(L"tags\*(R" file from the test suite and \fBmust not\fR be modified. .IP "\-" 4 Path to the \*(L"actual output\*(R" file (read-write) .Sp This is the file as lintian and post_test created it. .IP "\-" 4 Path to the \*(L"calibrated expected output\*(R" (create+write) .Sp This file does not exist and should be created by the script, if it wishes to change the \*(L"expected output\*(R". If this file exists when the script terminates, this file will be used instead of the original \&\*(L"expected output\*(R" file. .RE .RS 4 .RE .SH "SEE ALSO" .IX Header "SEE ALSO" The READMEs in the suites: \fIt/tests/README\fR, \fIt/changes/README\fR, \&\fIt/debs/README\fR and \fIt/source/README\fR. .PP Lintian::Tutorial::WritingChecks, Lintian::Tutorial::TestSuite