Change the testsuite files to be easily incorporated into an existing testsuite

* README: Rewrite the testuite section.
* wordsplit.at: Remove AT_INIT
* wsp.c: Include wordsplit-version.h before wordsplit.h
This commit is contained in:
Sergey Poznyakoff 2019-07-11 11:14:52 +03:00
parent 6ccb9ad200
commit 6a7581f2e6
3 changed files with 56 additions and 82 deletions

111
README
View file

@ -145,93 +145,69 @@ It is also possible to use LDADD as shown in the example below:
The package contains two files for building the testsuite: wsp.c,
which is used to build the auxiliary binary wsp, and wordsplit.at,
which is translated by GNU autotest into a testsuite shell script.
which can be included to a GNU autotest-based testsuite source.
The discussion below is for those who wish to include wordsplit
testsuite into their project. It assumes the following layout of the
hosting project:
lib/
Directory holding the library that incorporates wordsplit.o.
This discussion assumes the library name is libmy.a
lib/wordsplit
Wordsplit sources.
The testsuite will be built in lib.
testsuite into their project. It assumes that the hosting project
already has an autotest-based testsuite.
** Additional files
Three additional files are necessary for the testsuite: atlocal.in,
wordsplit-version.h, and package.m4.
The file atlocal.in is a simple shell script that sets the PATH
environment variable for the testsuite. It contains just one line:
PATH=$srcdir/wordsplit:$PATH
The file wordsplit-version.h provides the version definition for the
test program wsp.c. Use the following script to create it:
To build the auxiliary tool wsp, you will need an additional file,
wordsplit-version.h. Normally, it should contain only a definition
of the macro or variable WORDSPLIT_VERSION. The following shell
fragment can be used to create it:
version=$(cd wordsplit; git describe)
cat > wordsplit-version.h <<EOF
#define WORDSPLIT_VERSION "$version"
EOF
The file package.m4 contains package description which allows
testsuite to generate an accurate report. To create it, use:
This file should be listed in the EXTRA_DIST variable to make sure
it is distributed with the tarball.
cat > package.m4 <<EOF
m4_define([AT_PACKAGE_NAME], [wordsplit])
m4_define([AT_PACKAGE_TARNAME], [wordsplit])
m4_define([AT_PACKAGE_VERSION], [$version])
m4_define([AT_PACKAGE_STRING], [AT_PACKAGE_NAME AT_PACKAGE_VERSION])
m4_define([AT_PACKAGE_BUGREPORT], [gray@gnu.org])
EOF
** testsuite.at
Here, $version is the same variable you used for wordsplit-version.h.
Include the file wordsplit.at to your testsuite.at:
After creating the three files, list them in the EXTRA_DIST variable in
lib/Makefile.am to make sure they will be distributed with the tarball.
m4_include(wordsplit.at)
** configure.ac
** Makefile.am
Add the following lines to your configure.ac:
In the Makefile.am responsible for creating the testsuite, make sure
that the path to the wordsplit module is passed to the autotest
invocation, so that the above m4_include statement will work. The
usual make goal to build the testsuite looks as follows:
AM_MISSING_PROG([AUTOM4TE], [autom4te])
$(TESTSUITE): package.m4 $(TESTSUITE_AT)
$(AM_V_GEN)$(AUTOTEST) \
-I $(srcdir)\
-I $(top_srcdir)/wordsplit\
testsuite.at -o $@.tmp
$(AM_V_at)mv $@.tmp $@
AC_CONFIG_TESTDIR([lib])
AC_CONFIG_FILES([lib/Makefile lib/atlocal])
Then, add the following fragment to build the auxiliary files:
** lib/Makefile.am
# ###########################
# Wordsplit testsuite
# ###########################
EXTRA_DIST += wordsplit-version.h
$(srcdir)/wordsplit-version.h: $(top_srcdir)/configure.ac
$(AM_V_GEN){\
if test -e $(top_srcdir)/libmailutils/wordsplit/.git; then \
wsversion=$$(cd $(top_srcdir)/libmailutils/wordsplit; git describe); \
else \
wsversion="unknown"; \
fi;\
echo "#define WORDSPLIT_VERSION \"$wsversion\"";\
echo '#include <mailutils/wordsplit.h>'; } > \
> $(srcdir)/wordsplit-version.h
The Makefile.am in lib must be modified to build the auxiliary program
wsp and create the testsuite script. This is done by the following
fragment:
EXTRA_DIST = testsuite wordsplit/wordsplit.at package.m4
DISTCLEANFILES = atconfig
MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
TESTSUITE = $(srcdir)/testsuite
M4=m4
AUTOTEST = $(AUTOM4TE) --language=autotest
$(TESTSUITE): src/wordsplit.at
$(AM_V_GEN)$(AUTOTEST) -I $(srcdir) wordsplit/wordsplit.at \
-o $(TESTSUITE).tmp
$(AM_V_at)mv $(TESTSUITE).tmp $(TESTSUITE)
noinst_PROGRAMS = wsp
wsp_SOURCES = wordsplit/wsp.c wordsplit-version.h
wsp_LDADD = ./libmy.a
atconfig: $(top_builddir)/config.status
cd $(top_builddir) && ./config.status $@
clean-local:
@test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
check-local: atconfig atlocal $(TESTSUITE)
@$(SHELL) $(TESTSUITE)
noinst_PROGRAMS += wsp
wsp_SOURCES =
nodist_wsp_SOURCES = wsp.c
wsp.o: $(srcdir)/wordsplit-version.h
VPATH += $(top_srcdir)/libmailutils/wordsplit
* History
@ -314,4 +290,3 @@ mode: outline
paragraph-separate: "[ ]*$"
version-control: never
End:

View file

@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with wordsplit. If not, see <http://www.gnu.org/licenses/>.
AT_INIT
AT_TESTED(wsp)
m4_pushdef([wspnum],[0])

2
wsp.c
View file

@ -22,8 +22,8 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "wordsplit.h"
#include "wordsplit-version.h"
#include "wordsplit.h"
extern char **environ;