1 /* miniexpect test suite
2 * Copyright (C) 2014 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "miniexpect.h"
30 main (int argc, char *argv[])
37 pcre *multi_re = test_compile_re ("multi");
38 pcre *match_re = test_compile_re ("match");
39 pcre *ing_re = test_compile_re ("ing");
40 pcre *str_re = test_compile_re ("str");
41 pcre *s_re = test_compile_re ("s");
42 const int ovecsize = 12;
43 int ovector[ovecsize];
45 /* If the subprocess prints multiple things, we should be able to
46 * repeatedly call mexp_expect to match on each one. This didn't
47 * work correctly in earlier versions of the library.
49 h = mexp_spawnl ("echo", "echo", "multimatchingstrs", NULL);
52 for (i = 0; i < 5; ++i) {
61 }, ovector, ovecsize);
63 case 100: case 101: case 102: case 103: case 104:
64 printf ("iteration %zu: matched %d\n", i, r);
68 fprintf (stderr, "error: unexpected EOF in iteration %zu\n", i);
71 fprintf (stderr, "error: unexpected timeout in iteration %zu\n", i);
74 perror ("mexp_expect");
77 fprintf (stderr, "error: PCRE error: %d\n", h->pcre_error);
82 assert (rv[0] == 100); /* multi */
83 assert (rv[1] == 101); /* match */
84 assert (rv[2] == 102); /* ing */
85 assert (rv[3] == 103); /* str */
86 assert (rv[4] == 104); /* s */
88 status = mexp_close (h);
89 if (status != 0 && !test_is_sighup (status)) {
90 fprintf (stderr, "%s: non-zero exit status from subcommand: ", argv[0]);
91 test_diagnose (status);
92 fprintf (stderr, "\n");