Skip to content

Commit 7e110bd

Browse files
committed
Bug #11766640 59789: HOOK THE INVOCATION OF UNIT TESTS IN MTR.
Follow-up fix for regex tests on Windows: Rewrite test to run inline, rather than depending on external data file Addendum: fix [alnum] test by replacing locale-dependent letter with '5'.
1 parent a2488af commit 7e110bd

File tree

4 files changed

+521
-491
lines changed

4 files changed

+521
-491
lines changed

regex/CMakeLists.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
1818
SET(REGEX_SOURCES regcomp.c regerror.c regexec.c regfree.c reginit.c)
1919
ADD_CONVENIENCE_LIBRARY(regex ${REGEX_SOURCES})
2020

21-
ADD_EXECUTABLE(re main.c split.c debug.c)
22-
TARGET_LINK_LIBRARIES(re regex strings mysys)
21+
IF(WITH_UNIT_TESTS)
22+
ADD_EXECUTABLE(re main.c split.c debug.c)
23+
TARGET_LINK_LIBRARIES(re regex strings mysys)
2324

24-
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/tests
25-
${CMAKE_CURRENT_BINARY_DIR}/re_tests COPYONLY)
26-
27-
ADD_TEST(regex1 re -i${CMAKE_CURRENT_BINARY_DIR}/re_tests)
28-
ADD_TEST(regex2 re -el -i${CMAKE_CURRENT_BINARY_DIR}/re_tests)
29-
ADD_TEST(regex3 re -er -i${CMAKE_CURRENT_BINARY_DIR}/re_tests)
25+
ADD_TEST(regex1 re -I)
26+
ADD_TEST(regex2 re -el -I)
27+
ADD_TEST(regex3 re -er -I)
28+
ENDIF()

regex/main.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "my_regex.h"
77
#include "main.ih"
8+
#include "tests_include.h"
89

910
char *progname;
1011
int debug = 0;
@@ -65,14 +66,15 @@ char *argv[];
6566
size_t len;
6667
int c;
6768
int errflg = 0;
69+
int opt_inline = 0;
6870
register int i;
6971
char *input_file_name= NULL;
7072
extern int optind;
7173
extern char *optarg;
7274

7375
progname = argv[0];
7476

75-
while ((c = getopt(argc, argv, "c:e:i:S:E:x")) != EOF)
77+
while ((c = getopt(argc, argv, "c:e:i:S:E:xI")) != EOF)
7678
switch (c) {
7779
case 'c': /* compile options */
7880
copts = options('c', optarg);
@@ -92,6 +94,9 @@ char *argv[];
9294
case 'x': /* Debugging. */
9395
debug++;
9496
break;
97+
case 'I': /* Inline. */
98+
opt_inline= 1;
99+
break;
95100
case '?':
96101
default:
97102
errflg++;
@@ -100,10 +105,15 @@ char *argv[];
100105
if (errflg) {
101106
fprintf(stderr, "usage: %s ", progname);
102107
fprintf(stderr,
103-
"[-c copt][-e eopt][-i filename][-S][-E][-x] [re]\n");
108+
"[-c copt][-e eopt][-i filename][-S][-E][-x][-I] [re]\n");
104109
exit(2);
105110
}
106111

112+
if (opt_inline) {
113+
regress(NULL);
114+
exit(status);
115+
}
116+
107117
if (optind >= argc && !input_file_name) {
108118
regress(stdin);
109119
exit(status);
@@ -165,9 +175,24 @@ char *argv[];
165175
exit(status);
166176
}
167177

178+
char*
179+
get_next_line(s, size, stream)
180+
char *s;
181+
int size;
182+
FILE *stream;
183+
{
184+
if (stream)
185+
return fgets(s, size, stream);
186+
if (test_array[line])
187+
return strncpy(s, test_array[line], size);
188+
return NULL;
189+
}
190+
168191
/*
169192
- regress - main loop of regression test
170193
== void regress(FILE *in);
194+
Reads file, line-by-line.
195+
If in == NULL, we read data from test_array instead.
171196
*/
172197
void
173198
regress(in)
@@ -185,13 +210,14 @@ FILE *in;
185210
const char *bpname = "MY_REG_BADPAT";
186211
my_regex_t re;
187212

188-
while (fgets(inbuf, sizeof(inbuf), in) != NULL) {
213+
while (get_next_line(inbuf, sizeof(inbuf), in) != NULL) {
189214
line++;
190-
if (inbuf[0] == '#' || inbuf[0] == '\n')
215+
if (inbuf[0] == '#' || inbuf[0] == '\n' || inbuf[0] == '\0')
191216
continue; /* NOTE CONTINUE */
192-
inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */
217+
if (inbuf[strlen(inbuf)-1] == '\n')
218+
inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */
193219
if (debug)
194-
fprintf(stdout, "%d:\n", line);
220+
fprintf(stdout, "%d: <%s>\n", line, inbuf);
195221
nf = split(inbuf, f, MAXF, (char*) "\t\t");
196222
if (nf < 3) {
197223
fprintf(stderr, "bad input, line %d\n", line);

0 commit comments

Comments
 (0)