Skip to content

Commit bb23466

Browse files
committed
Allow running without parse transform with no loss of functionality
This allows running proper, with the `PROPER_NO_TRANS` flag, with no loss of functionality in practice, by replacing the implicit type usage introduced by the parse transform, by explicit calls to a new `?TYPE` macro. In practice, this is even more powerful than the parse transform. In particular, it's possible to define ad-hoc types with `?TYPE(X | Y)`, where before defining a one-off type alias was necessary.
1 parent cfc29e7 commit bb23466

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

include/proper_common.hrl

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
proper_types:add_constraint(RawType,fun(X) -> Condition end,true)).
6262
-define(SUCHTHATMAYBE(X,RawType,Condition),
6363
proper_types:add_constraint(RawType,fun(X) -> Condition end,false)).
64+
-define(TYPE(X), proper_types:native_type(?MODULE, ??X)).
6465

6566
%%------------------------------------------------------------------------------
6667
%% Targeted macros

test/no_transforms.erl

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
%%% -*- coding: utf-8 -*-
2+
%%% -*- erlang-indent-level: 2 -*-
3+
%%% -------------------------------------------------------------------
4+
%%% Copyright 2010-2011 Manolis Papadakis <[email protected]>,
5+
%%% Eirini Arvaniti <[email protected]>
6+
%%% and Kostis Sagonas <[email protected]>
7+
%%%
8+
%%% This file is part of PropEr.
9+
%%%
10+
%%% PropEr is free software: you can redistribute it and/or modify
11+
%%% it under the terms of the GNU General Public License as published by
12+
%%% the Free Software Foundation, either version 3 of the License, or
13+
%%% (at your option) any later version.
14+
%%%
15+
%%% PropEr is distributed in the hope that it will be useful,
16+
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
%%% GNU General Public License for more details.
19+
%%%
20+
%%% You should have received a copy of the GNU General Public License
21+
%%% along with PropEr. If not, see <http://www.gnu.org/licenses/>.
22+
23+
%%% @copyright 2010-2011 Manolis Papadakis, Eirini Arvaniti and Kostis Sagonas
24+
%%% @version {@version}
25+
%%% @doc This module tests whether proper works with parse transforms disabled.
26+
27+
-module(no_transforms).
28+
-export([prop_1/0]).
29+
30+
-define(PROPER_NO_TRANS, true).
31+
32+
-include_lib("proper/include/proper.hrl").
33+
34+
-type local_integer() :: integer().
35+
-type local_float() :: float().
36+
37+
prop_1() -> ?FORALL(X, ?TYPE(local_integer() | local_float()), is_number(X)).

test/proper_tests.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ parse_transform_test_() ->
837837
?_assertError(undef, auto_export_test2:prop_1()),
838838
?_assertError(undef, no_native_parse_test:prop_1()),
839839
?_passes(let_tests:prop_1()),
840-
?_failsWith([3*42], let_tests:prop_2())].
840+
?_failsWith([3*42], let_tests:prop_2()),
841+
?_passes(no_transforms:prop_1())].
841842

842843
native_type_props_test_() ->
843844
[?_passes(?FORALL({X,Y}, {my_native_type(),my_proper_type()},

0 commit comments

Comments
 (0)