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