Blame gnulib-tests/test-getprogname.c

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