aboutsummaryrefslogtreecommitdiffstats
path: root/lib/eunit/src/eunit_striptests.erl
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
committerErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
commit84adefa331c4159d432d22840663c38f155cd4c1 (patch)
treebff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/eunit/src/eunit_striptests.erl
downloadotp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz
otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2
otp-84adefa331c4159d432d22840663c38f155cd4c1.zip
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/eunit/src/eunit_striptests.erl')
-rw-r--r--lib/eunit/src/eunit_striptests.erl67
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/eunit/src/eunit_striptests.erl b/lib/eunit/src/eunit_striptests.erl
new file mode 100644
index 0000000000..606e44b286
--- /dev/null
+++ b/lib/eunit/src/eunit_striptests.erl
@@ -0,0 +1,67 @@
+%% This library is free software; you can redistribute it and/or modify
+%% it under the terms of the GNU Lesser General Public License as
+%% published by the Free Software Foundation; either version 2 of the
+%% License, or (at your option) any later version.
+%%
+%% This library is distributed in the hope that it will be useful, but
+%% WITHOUT ANY WARRANTY; without even the implied warranty of
+%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%% Lesser General Public License for more details.
+%%
+%% You should have received a copy of the GNU Lesser General Public
+%% License along with this library; if not, write to the Free Software
+%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+%% USA
+%%
+%% $Id: eunit_striptests.erl 329 2009-03-01 11:23:32Z rcarlsson $
+%%
+%% @author Richard Carlsson <[email protected]>
+%% @author Eric Merritt <[email protected]>
+%% @copyright 2006 Richard Carlsson, Eric Merritt
+%% @private
+%% @see eunit
+%% @doc Parse transform for stripping EUnit test functions.
+
+-module(eunit_striptests).
+
+-include("eunit_internal.hrl").
+
+-export([parse_transform/2]).
+
+parse_transform(Forms, Options) ->
+ TestSuffix = proplists:get_value(eunit_test_suffix, Options,
+ ?DEFAULT_TEST_SUFFIX),
+ GeneratorSuffix = proplists:get_value(eunit_generator_suffix,
+ Options,
+ ?DEFAULT_GENERATOR_SUFFIX),
+ ExportSuffix = proplists:get_value(eunit_export_suffix, Options,
+ ?DEFAULT_EXPORT_SUFFIX),
+ Exports = lists:foldl(fun ({attribute,_,export,Es}, S) ->
+ sets:union(sets:from_list(Es), S);
+ (_F, S) -> S
+ end,
+ sets:new(), Forms),
+ F = fun (Form, Acc) ->
+ form(Form, Acc, Exports, TestSuffix, GeneratorSuffix,
+ ExportSuffix)
+ end,
+ lists:reverse(lists:foldl(F, [], Forms)).
+
+form({function, _L, Name, 0, _Cs}=Form, Acc, Exports, TestSuffix,
+ GeneratorSuffix, ExportSuffix) ->
+ N = atom_to_list(Name),
+ case not sets:is_element({Name, 0}, Exports)
+ andalso (lists:suffix(TestSuffix, N)
+ orelse lists:suffix(GeneratorSuffix, N)
+ orelse lists:suffix(ExportSuffix, N))
+ of
+ true ->
+ Acc;
+ false ->
+ [Form | Acc]
+ end;
+form({function, _L, ?DEFAULT_MODULE_WRAPPER_NAME, 1, _Cs}, Acc, _, _, _,
+ _) ->
+ Acc;
+form(Form, Acc, _, _, _, _) ->
+ [Form | Acc].