Blame gnulib-tests/test-verify.c

Packit Service fdd496
/* Test the "verify" module.
Packit Service fdd496
Packit Service fdd496
   Copyright (C) 2005, 2009-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
/* Written by Bruno Haible.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
#include "verify.h"
Packit Service fdd496
Packit Service fdd496
#ifndef EXP_FAIL
Packit Service fdd496
# define EXP_FAIL 0
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
int x;
Packit Service fdd496
enum { a, b, c };
Packit Service fdd496
Packit Service fdd496
#if EXP_FAIL == 1
Packit Service fdd496
verify (x >= 0);                  /* should give ERROR: non-constant expression */
Packit Service fdd496
#endif
Packit Service fdd496
verify (c == 2);                  /* should be ok */
Packit Service fdd496
#if EXP_FAIL == 2
Packit Service fdd496
verify (1 + 1 == 3);              /* should give ERROR */
Packit Service fdd496
#endif
Packit Service fdd496
verify (1 == 1); verify (1 == 1); /* should be ok */
Packit Service fdd496
Packit Service fdd496
enum
Packit Service fdd496
{
Packit Service fdd496
  item = verify_true (1 == 1) * 0 + 17 /* should be ok */
Packit Service fdd496
};
Packit Service fdd496
Packit Service fdd496
static int
Packit Service fdd496
function (int n)
Packit Service fdd496
{
Packit Service fdd496
#if EXP_FAIL == 3
Packit Service fdd496
  verify (n >= 0);                  /* should give ERROR: non-constant expression */
Packit Service fdd496
#endif
Packit Service fdd496
  verify (c == 2);                  /* should be ok */
Packit Service fdd496
#if EXP_FAIL == 4
Packit Service fdd496
  verify (1 + 1 == 3);              /* should give ERROR */
Packit Service fdd496
#endif
Packit Service fdd496
  verify (1 == 1); verify (1 == 1); /* should be ok */
Packit Service fdd496
Packit Service fdd496
  if (n)
Packit Service fdd496
    return ((void) verify_expr (1 == 1, 1), verify_expr (1 == 1, 8)); /* should be ok */
Packit Service fdd496
#if EXP_FAIL == 5
Packit Service fdd496
  return verify_expr (1 == 2, 5); /* should give ERROR */
Packit Service fdd496
#endif
Packit Service fdd496
  return 0;
Packit Service fdd496
}
Packit Service fdd496
Packit Service fdd496
int
Packit Service fdd496
main (void)
Packit Service fdd496
{
Packit Service fdd496
  return !(function (0) == 0 && function (1) == 8);
Packit Service fdd496
}