1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2003-2007 Tim Kientzle
5 * All rights reserved.
6 */
7 #include "test.h"
8
9 /*
10 * This first test does basic sanity checks on the environment. For
11 * most of these, we just exit on failure.
12 */
13 #if !defined(_WIN32) || defined(__CYGWIN__)
14 #define DEV_NULL "/dev/null"
15 #else
16 #define DEV_NULL "NUL"
17 #endif
18
DEFINE_TEST(test_0)19 DEFINE_TEST(test_0)
20 {
21 struct stat st;
22
23 failure("File %s does not exist?!", testprog);
24 if (!assertEqualInt(0, stat(testprogfile, &st))) {
25 fprintf(stderr,
26 "\nFile %s does not exist; aborting test.\n\n",
27 testprog);
28 exit(1);
29 }
30
31 failure("%s is not executable?!", testprog);
32 if (!assert((st.st_mode & 0111) != 0)) {
33 fprintf(stderr,
34 "\nFile %s not executable; aborting test.\n\n",
35 testprog);
36 exit(1);
37 }
38
39 /*
40 * Try to successfully run the program; this requires that
41 * we know some option that will succeed.
42 */
43 if (0 == systemf("%s --version >" DEV_NULL, testprog)) {
44 /* This worked. */
45 } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) {
46 /* This worked. */
47 } else {
48 failure("Unable to successfully run any of the following:\n"
49 " * %s --version\n"
50 " * %s -W version\n",
51 testprog, testprog);
52 assert(0);
53 }
54
55 /* TODO: Ensure that our reference files are available. */
56 }
57