Blame gnulib-tests/test-getprogname.c

Packit Service fdd496
/* Test the gnulib getprogname module.
Packit Service fdd496
   Copyright (C) 2016-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
#include "getprogname.h"
Packit Service fdd496
#include <string.h>
Packit Service fdd496
#include <assert.h>
Packit Service fdd496
Packit Service fdd496
#ifdef __hpux
Packit Service fdd496
# define STREQ(a, b) (strncmp (a, b, 14) == 0)
Packit Service fdd496
#else
Packit Service fdd496
# define STREQ(a, b) (strcmp (a, b) == 0)
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
int
Packit Service fdd496
main (void)
Packit Service fdd496
{
Packit Service fdd496
  char const *p = getprogname ();
Packit Service fdd496
Packit Service fdd496
  /* libtool creates a temporary executable whose name is sometimes prefixed
Packit Service fdd496
     with "lt-" (depends on the platform).  But the name of the temporary
Packit Service fdd496
     executable is a detail that should not be visible to the end user and to
Packit Service fdd496
     the test suite.  Remove this "lt-" prefix here.  */
Packit Service fdd496
  if (strncmp (p, "lt-", 3) == 0)
Packit Service fdd496
    p += 3;
Packit Service fdd496
Packit Service fdd496
  /* Note: You can make this test fail
Packit Service fdd496
     a) by running it on a case-insensitive file system (such as on Windows,
Packit Service fdd496
        Cygwin, or on Mac OS X with a case-insensitive HFS+ file system),
Packit Service fdd496
        with an invocation that contains upper case characters, e.g.
Packit Service fdd496
        test-GETPROGNAME,
Packit Service fdd496
     b) by hardlinking or symlinking it to a different name (e.g. test-foo)
Packit Service fdd496
        and invoking it through that name.
Packit Service fdd496
     That's not the intended use. The Makefile always invokes it as
Packit Service fdd496
     'test-getprogname${EXEEXT}'. */
Packit Service fdd496
#if defined __CYGWIN__
Packit Service fdd496
  /* The Cygwin getprogname() function strips the ".exe" suffix. */
Packit Service fdd496
  assert (STREQ (p, "test-getprogname"));
Packit Service fdd496
#else
Packit Service fdd496
  assert (STREQ (p, "test-getprogname" EXEEXT));
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
  return 0;
Packit Service fdd496
}