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

135
README
View file

@ -15,21 +15,21 @@ The following code fragment shows the basic usage:
/* This variable controls parsing */ /* This variable controls parsing */
wordsplit_t ws; wordsplit_t ws;
int rc; int rc;
/* Provide variable definitions */ /* Provide variable definitions */
ws.ws_env = (const char **) environ; ws.ws_env = (const char **) environ;
/* Provide a function for expanding commands */ /* Provide a function for expanding commands */
ws.ws_command = runcom; ws.ws_command = runcom;
/* Split input_string into words */ /* Split input_string into words */
rc = wordsplit(input_string, &ws, rc = wordsplit(input_string, &ws,
WRDSF_QUOTE /* Handle both single and WRDSF_QUOTE /* Handle both single and
double quoted strings as words. */ double quoted strings as words. */
| WRDSF_SQUEEZE_DELIMS /* Compress adjacent delimiters */ | WRDSF_SQUEEZE_DELIMS /* Compress adjacent delimiters */
| WRDSF_PATHEXPAND /* Expand pathnames */ | WRDSF_PATHEXPAND /* Expand pathnames */
| WRDSF_SHOWERR); /* Show errors */ | WRDSF_SHOWERR); /* Show errors */
if (rc == 0) { if (rc == 0) {
/* Success. The resulting words are returned in the NULL-terminated /* Success. The resulting words are returned in the NULL-terminated
array ws.ws_wordv. Number of words is in ws.ws_wordc */ array ws.ws_wordv. Number of words is in ws.ws_wordc */
} }
/* Reclaim the allocated memory */ /* Reclaim the allocated memory */
wordsplit_free(&ws); wordsplit_free(&ws);
@ -80,19 +80,19 @@ Add the subdir-objects option to the invocation of AM_INIT_AUTOMAKE macro in
your configure.ac: your configure.ac:
AM_INIT_AUTOMAKE([subdir-objects]) AM_INIT_AUTOMAKE([subdir-objects])
In your Makefile.am, add both wordsplit/wordsplit.c and wordsplit/wordsplit.h In your Makefile.am, add both wordsplit/wordsplit.c and wordsplit/wordsplit.h
to the sources and -Iwordsplit to the cpp flags. For example: to the sources and -Iwordsplit to the cpp flags. For example:
program_SOURCES = main.c \ program_SOURCES = main.c \
wordsplit/wordsplit.c \ wordsplit/wordsplit.c \
wordsplit/wordsplit.h wordsplit/wordsplit.h
AM_CPPFLAGS = -I$(srcdir)/wordsplit AM_CPPFLAGS = -I$(srcdir)/wordsplit
You can also put wordsplit.h in the noinst_HEADERS variable, if you like: You can also put wordsplit.h in the noinst_HEADERS variable, if you like:
program_SOURCES = main.c \ program_SOURCES = main.c \
wordsplit/wordsplit.c wordsplit/wordsplit.c
noinst_HEADERS = wordsplit/wordsplit.h noinst_HEADERS = wordsplit/wordsplit.h
AM_CPPFLAGS = -I$(srcdir)/wordsplit AM_CPPFLAGS = -I$(srcdir)/wordsplit
@ -101,7 +101,7 @@ wordsplit API, install wordsplit.h to $(pkgincludedir), e.g.
lib_LTLIBRARIES = libmy.la lib_LTLIBRARIES = libmy.la
libmy_la_SOURCES = main.c \ libmy_la_SOURCES = main.c \
wordsplit/wordsplit.c wordsplit/wordsplit.c
AM_CPPFLAGS = -I$(srcdir)/wordsplit AM_CPPFLAGS = -I$(srcdir)/wordsplit
pkginclude_HEADERS = wordsplit/wordsplit.h pkginclude_HEADERS = wordsplit/wordsplit.h
@ -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, 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 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 The discussion below is for those who wish to include wordsplit
testsuite into their project. It assumes the following layout of the testsuite into their project. It assumes that the hosting project
hosting project: already has an autotest-based testsuite.
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.
** Additional files ** Additional files
Three additional files are necessary for the testsuite: atlocal.in, To build the auxiliary tool wsp, you will need an additional file,
wordsplit-version.h, and package.m4. wordsplit-version.h. Normally, it should contain only a definition
of the macro or variable WORDSPLIT_VERSION. The following shell
The file atlocal.in is a simple shell script that sets the PATH fragment can be used to create it:
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:
version=$(cd wordsplit; git describe) version=$(cd wordsplit; git describe)
cat > wordsplit-version.h <<EOF cat > wordsplit-version.h <<EOF
#define WORDSPLIT_VERSION "$version" #define WORDSPLIT_VERSION "$version"
EOF EOF
The file package.m4 contains package description which allows This file should be listed in the EXTRA_DIST variable to make sure
testsuite to generate an accurate report. To create it, use: it is distributed with the tarball.
cat > package.m4 <<EOF ** testsuite.at
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
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 m4_include(wordsplit.at)
lib/Makefile.am to make sure they will be distributed with the tarball.
** 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]) Then, add the following fragment to build the auxiliary files:
AC_CONFIG_FILES([lib/Makefile lib/atlocal])
** 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 noinst_PROGRAMS += wsp
wsp and create the testsuite script. This is done by the following wsp_SOURCES =
fragment: nodist_wsp_SOURCES = wsp.c
wsp.o: $(srcdir)/wordsplit-version.h
EXTRA_DIST = testsuite wordsplit/wordsplit.at package.m4 VPATH += $(top_srcdir)/libmailutils/wordsplit
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)
* History * History
@ -282,7 +258,7 @@ projects.
Git: <http://git.gnu.org.ua/cgit/fileserv.git> Git: <http://git.gnu.org.ua/cgit/fileserv.git>
[8] vmod-dbrw - Database-driven rewrite rules for Varnish Cache [8] vmod-dbrw - Database-driven rewrite rules for Varnish Cache
Home: <http://puszcza.gnu.org.ua/software/vmod-dbrw> Home: <http://puszcza.gnu.org.ua/software/vmod-dbrw>
Git: <http://git.gnu.org.ua/cgit/vmod-dbrw.git> Git: <http://git.gnu.org.ua/cgit/vmod-dbrw.git>
* Bug reporting * Bug reporting
@ -311,7 +287,6 @@ changed them.
Local Variables: Local Variables:
mode: outline mode: outline
paragraph-separate: "[ ]*$" paragraph-separate: "[ ]*$"
version-control: never version-control: never
End: End:

View file

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

2
wsp.c
View file

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