Blame lib/autotest/specific.m4

Packit 47b4ca
# This file is part of Autoconf.                          -*- Autoconf -*-
Packit 47b4ca
# M4 macros used in running tests using third-party testing tools.
Packit 47b4ca
m4_define([_AT_COPYRIGHT_YEARS],
Packit 47b4ca
[Copyright (C) 2009-2012 Free Software Foundation, Inc.])
Packit 47b4ca
Packit 47b4ca
# This file is part of Autoconf.  This program is free
Packit 47b4ca
# software; you can redistribute it and/or modify it under the
Packit 47b4ca
# terms of the GNU General Public License as published by the
Packit 47b4ca
# Free Software Foundation, either version 3 of the License, or
Packit 47b4ca
# (at your option) any later version.
Packit 47b4ca
#
Packit 47b4ca
# This program is distributed in the hope that it will be useful,
Packit 47b4ca
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 47b4ca
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 47b4ca
# GNU General Public License for more details.
Packit 47b4ca
#
Packit 47b4ca
# Under Section 7 of GPL version 3, you are granted additional
Packit 47b4ca
# permissions described in the Autoconf Configure Script Exception,
Packit 47b4ca
# version 3.0, as published by the Free Software Foundation.
Packit 47b4ca
#
Packit 47b4ca
# You should have received a copy of the GNU General Public License
Packit 47b4ca
# and a copy of the Autoconf Configure Script Exception along with
Packit 47b4ca
# this program; see the files COPYINGv3 and COPYING.EXCEPTION
Packit 47b4ca
# respectively.  If not, see <http://www.gnu.org/licenses/>.
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
## ------------------------ ##
Packit 47b4ca
## Erlang EUnit unit tests. ##
Packit 47b4ca
## ------------------------ ##
Packit 47b4ca
Packit 47b4ca
# AT_CHECK_EUNIT(MODULE, SPEC, [ERLFLAGS], [RUN-IF-FAIL], [RUN-IF-PASS])
Packit 47b4ca
# ----------------------------------------------------------------------
Packit 47b4ca
# Check that the EUnit test specification SPEC passes. The ERLFLAGS
Packit 47b4ca
# optional flags are passed to the Erlang interpreter command line to
Packit 47b4ca
# execute the test. The test is executed from an automatically
Packit 47b4ca
# generated Erlang module named MODULE. Each call to this macro should
Packit 47b4ca
# have a distinct MODULE name within each test group, to ease
Packit 47b4ca
# debugging.
Packit 47b4ca
# An Erlang/OTP version which contains the eunit library must be
Packit 47b4ca
# installed, in order to execute this macro in a test suite.  The ERL,
Packit 47b4ca
# ERLC, and ERLCFLAGS variables must be defined in atconfig,
Packit 47b4ca
# typically by using the AC_ERLANG_PATH_ERL and AC_ERLANG_PATH_ERLC
Packit 47b4ca
# Autoconf macros.
Packit 47b4ca
_AT_DEFINE_SETUP([AT_CHECK_EUNIT],
Packit 47b4ca
[AT_SKIP_IF([test ! -f "$ERL" || test ! -f "$ERLC"])
Packit 47b4ca
## A wrapper to EUnit, to exit the Erlang VM with the right exit code:
Packit 47b4ca
AT_DATA([$1.erl],
Packit 47b4ca
[[-module($1).
Packit 47b4ca
-export([test/0, test/1]).
Packit 47b4ca
test() -> test([]).
Packit 47b4ca
test(Options) ->
Packit 47b4ca
  TestSpec = $2,
Packit 47b4ca
  ReturnValue = case code:load_file(eunit) of
Packit 47b4ca
    {module, _} -> case eunit:test(TestSpec, Options) of
Packit 47b4ca
        ok -> "0\n"; %% test passes
Packit 47b4ca
        _  -> "1\n"  %% test fails
Packit 47b4ca
      end;
Packit 47b4ca
    _ -> "77\n" %% EUnit not found, test skipped
Packit 47b4ca
  end,
Packit 47b4ca
  file:write_file("$1.result", ReturnValue),
Packit 47b4ca
  init:stop().
Packit 47b4ca
]])
Packit 47b4ca
AT_CHECK(["$ERLC" $ERLCFLAGS -b beam $1.erl])
Packit 47b4ca
## Make EUnit verbose when testsuite is verbose:
Packit 47b4ca
if test -z "$at_verbose"; then
Packit 47b4ca
  at_eunit_options="verbose"
Packit 47b4ca
else
Packit 47b4ca
  at_eunit_options=""
Packit 47b4ca
fi
Packit 47b4ca
AT_CHECK(["$ERL" $3 -s $1 test $at_eunit_options -noshell], [0], [ignore], [],
Packit 47b4ca
         [$4], [$5])
Packit 47b4ca
AT_CAPTURE_FILE([$1.result])
Packit 47b4ca
AT_CHECK([test -f "$1.result" && (exit `cat "$1.result"`)])
Packit 47b4ca
])