xref: /netbsd-src/external/gpl3/autoconf/dist/lib/autotest/specific.m4 (revision d874e91932377fc40d53f102e48fc3ee6f4fe9de)
1# This file is part of Autoconf.                          -*- Autoconf -*-
2# M4 macros used in running tests using third-party testing tools.
3m4_define([_AT_COPYRIGHT_YEARS],
4[Copyright (C) 2009-2012 Free Software Foundation, Inc.])
5
6# This file is part of Autoconf.  This program is free
7# software; you can redistribute it and/or modify it under the
8# terms of the GNU General Public License as published by the
9# Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# Under Section 7 of GPL version 3, you are granted additional
18# permissions described in the Autoconf Configure Script Exception,
19# version 3.0, as published by the Free Software Foundation.
20#
21# You should have received a copy of the GNU General Public License
22# and a copy of the Autoconf Configure Script Exception along with
23# this program; see the files COPYINGv3 and COPYING.EXCEPTION
24# respectively.  If not, see <http://www.gnu.org/licenses/>.
25
26
27## ------------------------ ##
28## Erlang EUnit unit tests. ##
29## ------------------------ ##
30
31# AT_CHECK_EUNIT(MODULE, SPEC, [ERLFLAGS], [RUN-IF-FAIL], [RUN-IF-PASS])
32# ----------------------------------------------------------------------
33# Check that the EUnit test specification SPEC passes. The ERLFLAGS
34# optional flags are passed to the Erlang interpreter command line to
35# execute the test. The test is executed from an automatically
36# generated Erlang module named MODULE. Each call to this macro should
37# have a distinct MODULE name within each test group, to ease
38# debugging.
39# An Erlang/OTP version which contains the eunit library must be
40# installed, in order to execute this macro in a test suite.  The ERL,
41# ERLC, and ERLCFLAGS variables must be defined in atconfig,
42# typically by using the AC_ERLANG_PATH_ERL and AC_ERLANG_PATH_ERLC
43# Autoconf macros.
44_AT_DEFINE_SETUP([AT_CHECK_EUNIT],
45[AT_SKIP_IF([test ! -f "$ERL" || test ! -f "$ERLC"])
46## A wrapper to EUnit, to exit the Erlang VM with the right exit code:
47AT_DATA([$1.erl],
48[[-module($1).
49-export([test/0, test/1]).
50test() -> test([]).
51test(Options) ->
52  TestSpec = $2,
53  ReturnValue = case code:load_file(eunit) of
54    {module, _} -> case eunit:test(TestSpec, Options) of
55        ok -> "0\n"; %% test passes
56        _  -> "1\n"  %% test fails
57      end;
58    _ -> "77\n" %% EUnit not found, test skipped
59  end,
60  file:write_file("$1.result", ReturnValue),
61  init:stop().
62]])
63AT_CHECK(["$ERLC" $ERLCFLAGS -b beam $1.erl])
64## Make EUnit verbose when testsuite is verbose:
65if test -z "$at_verbose"; then
66  at_eunit_options="verbose"
67else
68  at_eunit_options=""
69fi
70AT_CHECK(["$ERL" $3 -s $1 test $at_eunit_options -noshell], [0], [ignore], [],
71         [$4], [$5])
72AT_CAPTURE_FILE([$1.result])
73AT_CHECK([test -f "$1.result" && (exit `cat "$1.result"`)])
74])
75