test-framework-sh: Don't leave temporary directories on NetBSD.
[gnulib.git] / tests / test-getprogname.c
blobf26696dbdbf6e7ce564bd81f38dffd2cfdb2e3fc
1 /* Test the gnulib getprogname module.
2 Copyright (C) 2016-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #include <stdlib.h>
21 #include <string.h>
22 #include <assert.h>
24 #ifdef __hpux
25 # define STREQ(a, b) (strncmp (a, b, 14) == 0)
26 #else
27 # define STREQ(a, b) (strcmp (a, b) == 0)
28 #endif
30 int
31 main (void)
33 char const *p = getprogname ();
35 /* libtool creates a temporary executable whose name is sometimes prefixed
36 with "lt-" (depends on the platform). But the name of the temporary
37 executable is a detail that should not be visible to the end user and to
38 the test suite. Remove this "lt-" prefix here. */
39 if (strncmp (p, "lt-", 3) == 0)
40 p += 3;
42 /* Note: You can make this test fail
43 a) by running it on a case-insensitive file system (such as on Windows,
44 Cygwin, or on Mac OS X with a case-insensitive HFS+ file system),
45 with an invocation that contains upper case characters, e.g.
46 test-GETPROGNAME,
47 b) by hardlinking or symlinking it to a different name (e.g. test-foo)
48 and invoking it through that name.
49 That's not the intended use. The Makefile always invokes it as
50 'test-getprogname${EXEEXT}'. */
51 #if defined __CYGWIN__
52 /* The Cygwin getprogname() function strips the ".exe" suffix. */
53 assert (STREQ (p, "test-getprogname"));
54 #else
55 assert (STREQ (p, "test-getprogname" EXEEXT));
56 #endif
58 return 0;