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 pcre2_code *multi_re = test_compile_re ("multi");
38 pcre2_code *match_re = test_compile_re ("match");
39 pcre2_code *ing_re = test_compile_re ("ing");
40 pcre2_code *str_re = test_compile_re ("str");
41 pcre2_code *s_re = test_compile_re ("s");
42 pcre2_match_data *match_data = pcre2_match_data_create (4, NULL);
44 /* If the subprocess prints multiple things, we should be able to
45 * repeatedly call mexp_expect to match on each one. This didn't
46 * work correctly in earlier versions of the library.
48 h = mexp_spawnl ("echo", "echo", "multimatchingstrs", NULL);
51 for (i = 0; i < 5; ++i) {
62 case 100: case 101: case 102: case 103: case 104:
63 printf ("iteration %zu: matched %d\n", i, r);
67 fprintf (stderr, "error: unexpected EOF in iteration %zu\n", i);
70 fprintf (stderr, "error: unexpected timeout in iteration %zu\n", i);
73 perror ("mexp_expect");
76 fprintf (stderr, "error: PCRE error: %d\n", mexp_get_pcre_error (h));
81 assert (rv[0] == 100); /* multi */
82 assert (rv[1] == 101); /* match */
83 assert (rv[2] == 102); /* ing */
84 assert (rv[3] == 103); /* str */
85 assert (rv[4] == 104); /* s */
87 status = mexp_close (h);
88 if (status != 0 && !test_is_sighup (status)) {
89 fprintf (stderr, "%s: non-zero exit status from subcommand: ", argv[0]);
90 test_diagnose (status);
91 fprintf (stderr, "\n");
95 pcre2_code_free (multi_re);
96 pcre2_code_free (match_re);
97 pcre2_code_free (ing_re);
98 pcre2_code_free (str_re);
99 pcre2_code_free (s_re);
100 pcre2_match_data_free (match_data);