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
19 /* Note this test depends on the output of 'ls --version'. You may
20 * have to extend the regular expressions below if running on a
33 #include "miniexpect.h"
37 main (int argc, char *argv[])
41 pcre *ls_coreutils_re;
43 const int ovecsize = 12;
44 int ovector[ovecsize];
47 ls_coreutils_re = test_compile_re ("^ls.* ([.\\d]+)");
48 /* Busybox doesn't actually recognize the --version option, but
49 * it prints out the version string in its error message.
51 ls_busybox_re = test_compile_re ("^BusyBox v([.\\d+]) ");
53 h = mexp_spawnl ("ls", "ls", "--version", NULL);
56 switch (mexp_expect (h,
58 { 100, ls_coreutils_re },
59 { 101, ls_busybox_re },
61 }, ovector, ovecsize)) {
64 /* Get the matched version number. */
65 r = pcre_get_substring (h->buffer, ovector, h->pcre_error, 1, &version);
67 fprintf (stderr, "error: PCRE error reading version substring: %d\n",
71 printf ("ls version = %s\n", version);
72 pcre_free_substring (version);
75 fprintf (stderr, "error: EOF before matching version string\n");
78 fprintf (stderr, "error: timeout before matching version string\n");
81 perror ("mexp_expect");
84 fprintf (stderr, "error: PCRE error: %d\n", h->pcre_error);
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");
96 pcre_free (ls_coreutils_re);
97 pcre_free (ls_busybox_re);