2 * Copyright (c) 2012 Jilles Tjoelker
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
40 static char *run_test(long classification, const char *label, int severity,
41 const char *text, const char *action, const char *tag);
54 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
55 "illegal option -- z", "refer to manual", "BSD:ls:001",
57 "BSD:ls: ERROR: illegal option -- z\n"
58 "TO FIX: refer to manual BSD:ls:001\n"
61 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
62 "illegal option -- z", "refer to manual", "BSD:ls:001",
63 "text:severity:action:tag",
64 "illegal option -- z: ERROR\n"
65 "TO FIX: refer to manual BSD:ls:001\n"
68 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
69 "illegal option -- z", "refer to manual", "BSD:ls:001",
71 "illegal option -- z\n"
74 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
75 "illegal option -- z", "refer to manual", "BSD:ls:001",
77 "ERROR: illegal option -- z\n"
80 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
81 "illegal option -- z", "refer to manual", "BSD:ls:001",
83 "BSD:ls: ERROR: illegal option -- z\n"
84 "TO FIX: refer to manual BSD:ls:001\n"
87 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
88 "illegal option -- z", "refer to manual", "BSD:ls:001",
89 "tag:severity:text:nothing:action",
90 "BSD:ls: ERROR: illegal option -- z\n"
91 "TO FIX: refer to manual BSD:ls:001\n"
94 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
95 "illegal option -- z", "refer to manual", "BSD:ls:001",
97 "BSD:ls: ERROR: illegal option -- z\n"
98 "TO FIX: refer to manual BSD:ls:001\n"
101 MM_UTIL | MM_PRINT, MM_NULLLBL, MM_ERROR,
102 "illegal option -- z", "refer to manual", "BSD:ls:001",
104 "ERROR: illegal option -- z\n"
105 "TO FIX: refer to manual BSD:ls:001\n"
108 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
109 "illegal option -- z", MM_NULLACT, MM_NULLTAG,
111 "BSD:ls: ERROR: illegal option -- z\n"
114 MM_UTIL | MM_NULLMC, "BSD:ls", MM_ERROR,
115 "illegal option -- z", "refer to manual", "BSD:ls:001",
120 MM_APPL | MM_PRINT, "ABCDEFGHIJ:abcdefghijklmn", MM_INFO,
121 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
122 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
123 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
124 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
125 "refer to manual", "ABCDEFGHIJ:abcdefghijklmn:001",
127 "ABCDEFGHIJ:abcdefghijklmn: INFO: "
128 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
129 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
130 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
131 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
132 "TO FIX: refer to manual ABCDEFGHIJ:abcdefghijklmn:001\n"
135 MM_OPSYS | MM_PRINT, "TEST:test", MM_HALT,
136 "failed", "nothing can help me", "NOTHING",
138 "TEST:test: HALT: failed\n"
139 "TO FIX: nothing can help me NOTHING\n"
142 MM_OPSYS | MM_PRINT, "TEST:test", MM_WARNING,
143 "failed", "nothing can help me", "NOTHING",
145 "TEST:test: WARNING: failed\n"
146 "TO FIX: nothing can help me NOTHING\n"
149 MM_OPSYS | MM_PRINT, "TEST:test", MM_NOSEV,
150 "failed", "nothing can help me", "NOTHING",
152 "TEST:test: failed\n"
153 "TO FIX: nothing can help me NOTHING\n"
158 run_test(long classification, const char *label, int severity,
159 const char *text, const char *action, const char *tag)
175 if (pip[1] != STDERR_FILENO &&
176 dup2(pip[1], STDERR_FILENO) == -1)
178 if (fmtmsg(classification, label, severity, text, action, tag)
186 result = malloc(resultsize);
188 while ((n = read(pip[0], p, result + resultsize - p - 1)) != 0) {
196 if (result + resultsize == p - 1) {
198 result = realloc(result, resultsize);
203 if (memchr(result, '\0', p - result) != NULL) {
209 while ((wpid = waitpid(pid, &status, 0)) == -1 && errno == EINTR)
228 n = sizeof(testcases) / sizeof(testcases[0]);
230 printf("1..%zu\n", n);
231 for (i = 0; i < n; i++) {
233 if (t->msgverb != NULL)
234 setenv("MSGVERB", t->msgverb, 1);
237 result = run_test(t->classification, t->label, t->severity,
238 t->text, t->action, t->tag);
239 if (result != NULL && strcmp(result, t->result) == 0)
240 printf("ok %zu - correct\n",
243 printf("not ok %zu - %s\n",
244 i + 1, result != NULL ? "incorrect" : "failed");