Date: Sun, 10 Jul 2011 16:05:51 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r223910 - in user/gabor/tre-integration/tools/test/regex: . regmatch tests Message-ID: <201107101605.p6AG5peY052550@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gabor Date: Sun Jul 10 16:05:51 2011 New Revision: 223910 URL: http://svn.freebsd.org/changeset/base/223910 Log: - Add a small test program and Makefile to test standard-conformance of the regex code. It uses a simple file format to store a string, a pattern and the expected matching offsets. The expected matches are compared to the actual ones. Added: user/gabor/tre-integration/tools/test/regex/ user/gabor/tre-integration/tools/test/regex/Makefile (contents, props changed) user/gabor/tre-integration/tools/test/regex/regmatch/ user/gabor/tre-integration/tools/test/regex/regmatch/Makefile (contents, props changed) user/gabor/tre-integration/tools/test/regex/regmatch/regmatch.c (contents, props changed) user/gabor/tre-integration/tools/test/regex/tests/ user/gabor/tre-integration/tools/test/regex/tests/basic.tests Added: user/gabor/tre-integration/tools/test/regex/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/gabor/tre-integration/tools/test/regex/Makefile Sun Jul 10 16:05:51 2011 (r223910) @@ -0,0 +1,23 @@ +# $FreeBSD$ + +SUBDIR= regmatch + +TESTS=basic.tests + +test: regmatch +.for t in ${TESTS} + @echo "=== Running test ${t} ===" + @for l in `cat tests/${t} | grep -ve '^#'`; do \ + str=`echo $${l} | cut -d \; -f 2`; \ + pat=`echo $${l} | cut -d \; -f 1`; \ + match=`echo $${l} | cut -d \; -f 3`; \ + result=`./regmatch/regmatch $${pat} $${str}`; \ + if [ "$${match}" != "$${result}" ]; then \ + echo "Failed matching pattern $${pat} to string $${str}"; \ + else \ + echo "PASSED matching pattern $${pat} to string $${str}"; \ + fi \ + done +.endfor + +.include <bsd.prog.mk> Added: user/gabor/tre-integration/tools/test/regex/regmatch/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/gabor/tre-integration/tools/test/regex/regmatch/Makefile Sun Jul 10 16:05:51 2011 (r223910) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +PROG= regmatch +NO_MAN= yes + +WARNS?= 6 + +.include <bsd.prog.mk> Added: user/gabor/tre-integration/tools/test/regex/regmatch/regmatch.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/gabor/tre-integration/tools/test/regex/regmatch/regmatch.c Sun Jul 10 16:05:51 2011 (r223910) @@ -0,0 +1,51 @@ +#include <err.h> +#include <regex.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void +usage(void) +{ + printf("Usage: %s pattern string\n", getprogname()); + exit(EXIT_FAILURE); +} + +int +main(int argc, char *argv[]) +{ + regex_t pattern; + regmatch_t pmatch; + ssize_t len; + int cflags = 0, ret; + int eflags = REG_STARTEND; + + if (argc != 3) + usage(); + + ret = regcomp(&pattern, argv[1], cflags); + if (ret != 0) + errx(1, NULL); + + len = strlen(argv[2]); + pmatch.rm_so = 0; + pmatch.rm_eo = len; + putchar('('); + for (bool first = true;;) { + ret = regexec(&pattern, argv[2], 1, &pmatch, eflags); + if (ret == REG_NOMATCH) + break; + if (!first) + putchar(','); + printf("(%lu,%lu)", (unsigned long)pmatch.rm_so, + (unsigned long)pmatch.rm_eo); + if (pmatch.rm_eo == len) + break; + pmatch.rm_so = pmatch.rm_eo; + pmatch.rm_eo = len; + first = false; + } + printf(")\n"); + regfree(&pattern); +} Added: user/gabor/tre-integration/tools/test/regex/tests/basic.tests ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/gabor/tre-integration/tools/test/regex/tests/basic.tests Sun Jul 10 16:05:51 2011 (r223910) @@ -0,0 +1,3 @@ +# $FreeBSD$ + +foo;foobarfoobar;((0,3),(6,9))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107101605.p6AG5peY052550>