diff --git a/Makefile b/Makefile index d278d93..f47701f 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,16 @@ all: build %.beam: %.erl - erlc -o test/ $< + erlc -o test_etap/ $< build: c_src/decoder.c ./rebar compile -check: test/etap.beam test/util.beam - prove test/*.t +check: test_etap/etap.beam test_etap/util.beam + prove test_etap/*.t clean: rm -rf logs .eunit -ct: - ./rebar ct skip_deps=true verbose=1 +eunit: + ./rebar eunit skip_deps=true diff --git a/rebar b/rebar index c55b6e7..fc5a38e 100755 Binary files a/rebar and b/rebar differ diff --git a/rebar.config b/rebar.config index 7ee1bcd..b8371a9 100644 --- a/rebar.config +++ b/rebar.config @@ -16,7 +16,7 @@ {"darwin10.*-32$", "LDFLAGS", "-arch i386"} ]}. -{eunit_opts, [{file, "test/props.erl"}]}. +{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}. {deps, [{proper_stdlib, ".*", {git, "https://github.com/spawngrid/proper_stdlib.git", "master"}}, diff --git a/test/jiffy_SUITE.erl b/test/jiffy_SUITE.erl deleted file mode 100644 index 0806037..0000000 --- a/test/jiffy_SUITE.erl +++ /dev/null @@ -1,25 +0,0 @@ --module(jiffy_SUITE). --include_lib("proper/include/proper.hrl"). --include_lib("proper_stdlib/include/proper_ct.hrl"). --compile(export_all). - -all() -> proper_ct:testcases(?MODULE). - -init_per_testcase(tc_prop_foo, Config) -> - [{proper, [{numtests, 1000}]} | Config]. - --type json_any() :: json_list() - | json_dict() - | json_number() - | json_string() - | json_null(). --type json_list() :: list(json_any()). --type json_dict() :: {[{json_key(), json_any()}]}. --type json_key() :: binary(). --type json_number() :: integer() | float(). --type json_string() :: binary(). --type json_null() :: null. - -prop_foo() -> - ?FORALL(Data, json_any(), - Data == jiffy:decode(jiffy:encode(Data))). diff --git a/test/proper_tests.erl b/test/proper_tests.erl new file mode 100644 index 0000000..1bccf40 --- /dev/null +++ b/test/proper_tests.erl @@ -0,0 +1,89 @@ +-module(proper_tests). +-include_lib("proper/include/proper.hrl"). +%%-include_lib("proper_stdlib/include/proper_ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-export([proper_test_/0]). + +all() -> proper_ct:testcases(?MODULE). + +init_per_testcase(tc_prop_foo, Config) -> + [{proper, [{numtests, 1000}]} | Config]. + +-type json_any() :: json_list() + | json_dict() + | json_number() + | json_string() + | json_null(). +-type json_list() :: list(json_any()). +-type json_dict() :: {[{json_key(), json_any()}]}. +-type json_key() :: binary(). +-type json_number() :: integer() | float(). +-type json_string() :: binary(). +-type json_null() :: null. + +%% Atomic types +json_null() -> + null. + +json_string() -> + ?LET(Str, proper_stdgen:utf8_bin(), + binary:replace(Str, <<"\"">>, <<"\\\"">>, [global])). %good enough + +json_number() -> + oneof([integer(), float()]). + +json_boolean() -> + oneof([true, false]). + +json_atomic() -> + oneof([json_null(), + json_string(), + json_number(), + json_boolean()]). + +%% Compound types +json_object() -> + ?SIZED(S, json_object(S)). +json_object(0) -> + json_atomic(); +json_object(S) -> + frequency([{1, json_object(0)}, + {3, json_list()}, + {9, ?LAZY( + ?LETSHRINK( + [Node], + [{list({json_string(), json_object(S - 1)})}], + Node + ))}]). + +json_list() -> + list(json_object()). + +tree(G) -> + ?SIZED(S, tree(S, G)). +tree(0, _) -> + leaf; +tree(S, G) -> + frequency([ + {1, tree(0, G)}, + {9, ?LAZY( + ?LETSHRINK( + [L, R], + [tree(S div 2, G), tree(S div 2, G)], + {node, G, L, R} + ))} + ]). + +prop_foo() -> +%% ?FORALL(Data, json_any(), +%% Data == jiffy:decode(jiffy:encode(Data))). + ?FORALL(Data, json_object(), + begin + %io:format(user, "Data: ~p~n", [Data]), + Data == jiffy:decode(jiffy:encode(Data)) + end). + +proper_test_() -> + {timeout, 600, + ?_assertEqual([], proper:module(proper_tests, [{to_file, user}, + {numtests, 10}]))}. diff --git a/test/001-yajl-tests.t b/test_etap/001-yajl-tests.t similarity index 89% rename from test/001-yajl-tests.t rename to test_etap/001-yajl-tests.t index c8db641..2dc241e 100755 --- a/test/001-yajl-tests.t +++ b/test_etap/001-yajl-tests.t @@ -3,7 +3,7 @@ % See the LICENSE file for more information. main([]) -> - code:add_pathz("test"), + code:add_pathz("test_etap"), code:add_pathz("ebin"), Cases = read_cases(), @@ -18,7 +18,7 @@ test({Name, Json, Erl}) -> etap:is(jiffy:decode(Json), Erl, Name). read_cases() -> - CasesPath = filename:join(["test", "cases", "*.json"]), + CasesPath = filename:join(["test_etap", "cases", "*.json"]), FileNames = lists:sort(filelib:wildcard(CasesPath)), lists:map(fun(F) -> make_pair(F) end, FileNames). diff --git a/test/002-literals.t b/test_etap/002-literals.t similarity index 94% rename from test/002-literals.t rename to test_etap/002-literals.t index 8df7255..0bf6c4e 100755 --- a/test/002-literals.t +++ b/test_etap/002-literals.t @@ -4,7 +4,7 @@ main([]) -> code:add_pathz("ebin"), - code:add_pathz("test"), + code:add_pathz("test_etap"), etap:plan(6), etap:is(jiffy:decode(<<"true">>), true, "DEC: true -> true"), @@ -17,5 +17,3 @@ main([]) -> etap:is(jiffy:encode(null), <<"null">>, "ENC: null -> null"), etap:end_tests(). - - diff --git a/test/003-numbers.t b/test_etap/003-numbers.t similarity index 98% rename from test/003-numbers.t rename to test_etap/003-numbers.t index 42d26fd..dee24d5 100755 --- a/test/003-numbers.t +++ b/test_etap/003-numbers.t @@ -4,7 +4,7 @@ main([]) -> code:add_pathz("ebin"), - code:add_pathz("test"), + code:add_pathz("test_etap"), etap:plan(59), util:test_good(good()), diff --git a/test/004-strings.t b/test_etap/004-strings.t similarity index 98% rename from test/004-strings.t rename to test_etap/004-strings.t index 8396bbd..8d6ceae 100755 --- a/test/004-strings.t +++ b/test_etap/004-strings.t @@ -4,7 +4,7 @@ main([]) -> code:add_pathz("ebin"), - code:add_pathz("test"), + code:add_pathz("test_etap"), etap:plan(83), util:test_good(good()), diff --git a/test/005-arrays.t b/test_etap/005-arrays.t similarity index 96% rename from test/005-arrays.t rename to test_etap/005-arrays.t index 53ffd2f..fdc2588 100755 --- a/test/005-arrays.t +++ b/test_etap/005-arrays.t @@ -4,7 +4,7 @@ main([]) -> code:add_pathz("ebin"), - code:add_pathz("test"), + code:add_pathz("test_etap"), etap:plan(18), util:test_good(good()), diff --git a/test/006-maps.t b/test_etap/006-maps.t similarity index 96% rename from test/006-maps.t rename to test_etap/006-maps.t index 45e715c..a18081e 100755 --- a/test/006-maps.t +++ b/test_etap/006-maps.t @@ -4,7 +4,7 @@ main([]) -> code:add_pathz("ebin"), - code:add_pathz("test"), + code:add_pathz("test_etap"), etap:plan(15), util:test_good(good()), diff --git a/test/007-compound.t b/test_etap/007-compound.t similarity index 96% rename from test/007-compound.t rename to test_etap/007-compound.t index 2770971..6054198 100755 --- a/test/007-compound.t +++ b/test_etap/007-compound.t @@ -4,7 +4,7 @@ main([]) -> code:add_pathz("ebin"), - code:add_pathz("test"), + code:add_pathz("test_etap"), etap:plan(12), util:test_good(good()), diff --git a/test/008-halfword.t b/test_etap/008-halfword.t similarity index 91% rename from test/008-halfword.t rename to test_etap/008-halfword.t index 56f0439..7d62e33 100755 --- a/test/008-halfword.t +++ b/test_etap/008-halfword.t @@ -4,7 +4,7 @@ main([]) -> code:add_pathz("ebin"), - code:add_pathz("test"), + code:add_pathz("test_etap"), etap:plan(unknown), @@ -12,4 +12,3 @@ main([]) -> etap:is(jiffy:decode(<<"1">>) == 1, true, "1 == 1"), etap:end_tests(). - diff --git a/test/cases/array.erl b/test_etap/cases/array.erl similarity index 100% rename from test/cases/array.erl rename to test_etap/cases/array.erl diff --git a/test/cases/array.json b/test_etap/cases/array.json similarity index 100% rename from test/cases/array.json rename to test_etap/cases/array.json diff --git a/test/cases/array_close.erl b/test_etap/cases/array_close.erl similarity index 100% rename from test/cases/array_close.erl rename to test_etap/cases/array_close.erl diff --git a/test/cases/array_close.json b/test_etap/cases/array_close.json similarity index 100% rename from test/cases/array_close.json rename to test_etap/cases/array_close.json diff --git a/test/cases/array_open.erl b/test_etap/cases/array_open.erl similarity index 100% rename from test/cases/array_open.erl rename to test_etap/cases/array_open.erl diff --git a/test/cases/array_open.json b/test_etap/cases/array_open.json similarity index 100% rename from test/cases/array_open.json rename to test_etap/cases/array_open.json diff --git a/test/cases/bogus_char.erl b/test_etap/cases/bogus_char.erl similarity index 100% rename from test/cases/bogus_char.erl rename to test_etap/cases/bogus_char.erl diff --git a/test/cases/bogus_char.json b/test_etap/cases/bogus_char.json similarity index 100% rename from test/cases/bogus_char.json rename to test_etap/cases/bogus_char.json diff --git a/test/cases/codepoints_from_unicode_org.erl b/test_etap/cases/codepoints_from_unicode_org.erl similarity index 100% rename from test/cases/codepoints_from_unicode_org.erl rename to test_etap/cases/codepoints_from_unicode_org.erl diff --git a/test/cases/codepoints_from_unicode_org.json b/test_etap/cases/codepoints_from_unicode_org.json similarity index 100% rename from test/cases/codepoints_from_unicode_org.json rename to test_etap/cases/codepoints_from_unicode_org.json diff --git a/test/cases/deep_arrays.erl b/test_etap/cases/deep_arrays.erl similarity index 100% rename from test/cases/deep_arrays.erl rename to test_etap/cases/deep_arrays.erl diff --git a/test/cases/deep_arrays.json b/test_etap/cases/deep_arrays.json similarity index 100% rename from test/cases/deep_arrays.json rename to test_etap/cases/deep_arrays.json diff --git a/test/cases/difficult_json_c_test_case.erl b/test_etap/cases/difficult_json_c_test_case.erl similarity index 100% rename from test/cases/difficult_json_c_test_case.erl rename to test_etap/cases/difficult_json_c_test_case.erl diff --git a/test/cases/difficult_json_c_test_case.json b/test_etap/cases/difficult_json_c_test_case.json similarity index 100% rename from test/cases/difficult_json_c_test_case.json rename to test_etap/cases/difficult_json_c_test_case.json diff --git a/test/cases/doubles.erl b/test_etap/cases/doubles.erl similarity index 100% rename from test/cases/doubles.erl rename to test_etap/cases/doubles.erl diff --git a/test/cases/doubles.json b/test_etap/cases/doubles.json similarity index 100% rename from test/cases/doubles.json rename to test_etap/cases/doubles.json diff --git a/test/cases/empty_array.erl b/test_etap/cases/empty_array.erl similarity index 100% rename from test/cases/empty_array.erl rename to test_etap/cases/empty_array.erl diff --git a/test/cases/empty_array.json b/test_etap/cases/empty_array.json similarity index 100% rename from test/cases/empty_array.json rename to test_etap/cases/empty_array.json diff --git a/test/cases/empty_string.erl b/test_etap/cases/empty_string.erl similarity index 100% rename from test/cases/empty_string.erl rename to test_etap/cases/empty_string.erl diff --git a/test/cases/empty_string.json b/test_etap/cases/empty_string.json similarity index 100% rename from test/cases/empty_string.json rename to test_etap/cases/empty_string.json diff --git a/test/cases/escaped_bulgarian.erl b/test_etap/cases/escaped_bulgarian.erl similarity index 100% rename from test/cases/escaped_bulgarian.erl rename to test_etap/cases/escaped_bulgarian.erl diff --git a/test/cases/escaped_bulgarian.json b/test_etap/cases/escaped_bulgarian.json similarity index 100% rename from test/cases/escaped_bulgarian.json rename to test_etap/cases/escaped_bulgarian.json diff --git a/test/cases/escaped_foobar.erl b/test_etap/cases/escaped_foobar.erl similarity index 100% rename from test/cases/escaped_foobar.erl rename to test_etap/cases/escaped_foobar.erl diff --git a/test/cases/escaped_foobar.json b/test_etap/cases/escaped_foobar.json similarity index 100% rename from test/cases/escaped_foobar.json rename to test_etap/cases/escaped_foobar.json diff --git a/test/cases/false.erl b/test_etap/cases/false.erl similarity index 100% rename from test/cases/false.erl rename to test_etap/cases/false.erl diff --git a/test/cases/false.json b/test_etap/cases/false.json similarity index 100% rename from test/cases/false.json rename to test_etap/cases/false.json diff --git a/test/cases/false_then_garbage.erl b/test_etap/cases/false_then_garbage.erl similarity index 100% rename from test/cases/false_then_garbage.erl rename to test_etap/cases/false_then_garbage.erl diff --git a/test/cases/false_then_garbage.json b/test_etap/cases/false_then_garbage.json similarity index 100% rename from test/cases/false_then_garbage.json rename to test_etap/cases/false_then_garbage.json diff --git a/test/cases/four_byte_utf8.erl b/test_etap/cases/four_byte_utf8.erl similarity index 100% rename from test/cases/four_byte_utf8.erl rename to test_etap/cases/four_byte_utf8.erl diff --git a/test/cases/four_byte_utf8.json b/test_etap/cases/four_byte_utf8.json similarity index 100% rename from test/cases/four_byte_utf8.json rename to test_etap/cases/four_byte_utf8.json diff --git a/test/cases/integers.erl b/test_etap/cases/integers.erl similarity index 100% rename from test/cases/integers.erl rename to test_etap/cases/integers.erl diff --git a/test/cases/integers.json b/test_etap/cases/integers.json similarity index 100% rename from test/cases/integers.json rename to test_etap/cases/integers.json diff --git a/test/cases/invalid_utf8.erl b/test_etap/cases/invalid_utf8.erl similarity index 100% rename from test/cases/invalid_utf8.erl rename to test_etap/cases/invalid_utf8.erl diff --git a/test/cases/invalid_utf8.json b/test_etap/cases/invalid_utf8.json similarity index 100% rename from test/cases/invalid_utf8.json rename to test_etap/cases/invalid_utf8.json diff --git a/test/cases/isolated_surrogate_marker.erl b/test_etap/cases/isolated_surrogate_marker.erl similarity index 100% rename from test/cases/isolated_surrogate_marker.erl rename to test_etap/cases/isolated_surrogate_marker.erl diff --git a/test/cases/isolated_surrogate_marker.json b/test_etap/cases/isolated_surrogate_marker.json similarity index 100% rename from test/cases/isolated_surrogate_marker.json rename to test_etap/cases/isolated_surrogate_marker.json diff --git a/test/cases/leading_zero_in_number.erl b/test_etap/cases/leading_zero_in_number.erl similarity index 100% rename from test/cases/leading_zero_in_number.erl rename to test_etap/cases/leading_zero_in_number.erl diff --git a/test/cases/leading_zero_in_number.json b/test_etap/cases/leading_zero_in_number.json similarity index 100% rename from test/cases/leading_zero_in_number.json rename to test_etap/cases/leading_zero_in_number.json diff --git a/test/cases/lonely_minus_sign.erl b/test_etap/cases/lonely_minus_sign.erl similarity index 100% rename from test/cases/lonely_minus_sign.erl rename to test_etap/cases/lonely_minus_sign.erl diff --git a/test/cases/lonely_minus_sign.json b/test_etap/cases/lonely_minus_sign.json similarity index 100% rename from test/cases/lonely_minus_sign.json rename to test_etap/cases/lonely_minus_sign.json diff --git a/test/cases/lonely_number.erl b/test_etap/cases/lonely_number.erl similarity index 100% rename from test/cases/lonely_number.erl rename to test_etap/cases/lonely_number.erl diff --git a/test/cases/lonely_number.json b/test_etap/cases/lonely_number.json similarity index 100% rename from test/cases/lonely_number.json rename to test_etap/cases/lonely_number.json diff --git a/test/cases/map_close.erl b/test_etap/cases/map_close.erl similarity index 100% rename from test/cases/map_close.erl rename to test_etap/cases/map_close.erl diff --git a/test/cases/map_close.json b/test_etap/cases/map_close.json similarity index 100% rename from test/cases/map_close.json rename to test_etap/cases/map_close.json diff --git a/test/cases/map_open.erl b/test_etap/cases/map_open.erl similarity index 100% rename from test/cases/map_open.erl rename to test_etap/cases/map_open.erl diff --git a/test/cases/map_open.json b/test_etap/cases/map_open.json similarity index 100% rename from test/cases/map_open.json rename to test_etap/cases/map_open.json diff --git a/test/cases/missing_integer_after_decimal_point.erl b/test_etap/cases/missing_integer_after_decimal_point.erl similarity index 100% rename from test/cases/missing_integer_after_decimal_point.erl rename to test_etap/cases/missing_integer_after_decimal_point.erl diff --git a/test/cases/missing_integer_after_decimal_point.json b/test_etap/cases/missing_integer_after_decimal_point.json similarity index 100% rename from test/cases/missing_integer_after_decimal_point.json rename to test_etap/cases/missing_integer_after_decimal_point.json diff --git a/test/cases/missing_integer_after_exponent.erl b/test_etap/cases/missing_integer_after_exponent.erl similarity index 100% rename from test/cases/missing_integer_after_exponent.erl rename to test_etap/cases/missing_integer_after_exponent.erl diff --git a/test/cases/missing_integer_after_exponent.json b/test_etap/cases/missing_integer_after_exponent.json similarity index 100% rename from test/cases/missing_integer_after_exponent.json rename to test_etap/cases/missing_integer_after_exponent.json diff --git a/test/cases/non_utf8_char_in_string.erl b/test_etap/cases/non_utf8_char_in_string.erl similarity index 100% rename from test/cases/non_utf8_char_in_string.erl rename to test_etap/cases/non_utf8_char_in_string.erl diff --git a/test/cases/non_utf8_char_in_string.json b/test_etap/cases/non_utf8_char_in_string.json similarity index 100% rename from test/cases/non_utf8_char_in_string.json rename to test_etap/cases/non_utf8_char_in_string.json diff --git a/test/cases/null.erl b/test_etap/cases/null.erl similarity index 100% rename from test/cases/null.erl rename to test_etap/cases/null.erl diff --git a/test/cases/null.json b/test_etap/cases/null.json similarity index 100% rename from test/cases/null.json rename to test_etap/cases/null.json diff --git a/test/cases/null_then_garbage.erl b/test_etap/cases/null_then_garbage.erl similarity index 100% rename from test/cases/null_then_garbage.erl rename to test_etap/cases/null_then_garbage.erl diff --git a/test/cases/null_then_garbage.json b/test_etap/cases/null_then_garbage.json similarity index 100% rename from test/cases/null_then_garbage.json rename to test_etap/cases/null_then_garbage.json diff --git a/test/cases/nulls_and_bools.erl b/test_etap/cases/nulls_and_bools.erl similarity index 100% rename from test/cases/nulls_and_bools.erl rename to test_etap/cases/nulls_and_bools.erl diff --git a/test/cases/nulls_and_bools.json b/test_etap/cases/nulls_and_bools.json similarity index 100% rename from test/cases/nulls_and_bools.json rename to test_etap/cases/nulls_and_bools.json diff --git a/test/cases/simple.erl b/test_etap/cases/simple.erl similarity index 100% rename from test/cases/simple.erl rename to test_etap/cases/simple.erl diff --git a/test/cases/simple.json b/test_etap/cases/simple.json similarity index 100% rename from test/cases/simple.json rename to test_etap/cases/simple.json diff --git a/test/cases/string_invalid_escape.erl b/test_etap/cases/string_invalid_escape.erl similarity index 100% rename from test/cases/string_invalid_escape.erl rename to test_etap/cases/string_invalid_escape.erl diff --git a/test/cases/string_invalid_escape.json b/test_etap/cases/string_invalid_escape.json similarity index 100% rename from test/cases/string_invalid_escape.json rename to test_etap/cases/string_invalid_escape.json diff --git a/test/cases/string_invalid_hex_char.erl b/test_etap/cases/string_invalid_hex_char.erl similarity index 100% rename from test/cases/string_invalid_hex_char.erl rename to test_etap/cases/string_invalid_hex_char.erl diff --git a/test/cases/string_invalid_hex_char.json b/test_etap/cases/string_invalid_hex_char.json similarity index 100% rename from test/cases/string_invalid_hex_char.json rename to test_etap/cases/string_invalid_hex_char.json diff --git a/test/cases/string_with_escapes.erl b/test_etap/cases/string_with_escapes.erl similarity index 100% rename from test/cases/string_with_escapes.erl rename to test_etap/cases/string_with_escapes.erl diff --git a/test/cases/string_with_escapes.json b/test_etap/cases/string_with_escapes.json similarity index 100% rename from test/cases/string_with_escapes.json rename to test_etap/cases/string_with_escapes.json diff --git a/test/cases/string_with_invalid_newline.erl b/test_etap/cases/string_with_invalid_newline.erl similarity index 100% rename from test/cases/string_with_invalid_newline.erl rename to test_etap/cases/string_with_invalid_newline.erl diff --git a/test/cases/string_with_invalid_newline.json b/test_etap/cases/string_with_invalid_newline.json similarity index 100% rename from test/cases/string_with_invalid_newline.json rename to test_etap/cases/string_with_invalid_newline.json diff --git a/test/cases/three_byte_utf8.erl b/test_etap/cases/three_byte_utf8.erl similarity index 100% rename from test/cases/three_byte_utf8.erl rename to test_etap/cases/three_byte_utf8.erl diff --git a/test/cases/three_byte_utf8.json b/test_etap/cases/three_byte_utf8.json similarity index 100% rename from test/cases/three_byte_utf8.json rename to test_etap/cases/three_byte_utf8.json diff --git a/test/cases/true.erl b/test_etap/cases/true.erl similarity index 100% rename from test/cases/true.erl rename to test_etap/cases/true.erl diff --git a/test/cases/true.json b/test_etap/cases/true.json similarity index 100% rename from test/cases/true.json rename to test_etap/cases/true.json diff --git a/test/cases/true_then_garbage.erl b/test_etap/cases/true_then_garbage.erl similarity index 100% rename from test/cases/true_then_garbage.erl rename to test_etap/cases/true_then_garbage.erl diff --git a/test/cases/true_then_garbage.json b/test_etap/cases/true_then_garbage.json similarity index 100% rename from test/cases/true_then_garbage.json rename to test_etap/cases/true_then_garbage.json diff --git a/test/cases/unescaped_bulgarian.erl b/test_etap/cases/unescaped_bulgarian.erl similarity index 100% rename from test/cases/unescaped_bulgarian.erl rename to test_etap/cases/unescaped_bulgarian.erl diff --git a/test/cases/unescaped_bulgarian.json b/test_etap/cases/unescaped_bulgarian.json similarity index 100% rename from test/cases/unescaped_bulgarian.json rename to test_etap/cases/unescaped_bulgarian.json diff --git a/test/etap.erl b/test_etap/etap.erl similarity index 100% rename from test/etap.erl rename to test_etap/etap.erl diff --git a/test/util.erl b/test_etap/util.erl similarity index 100% rename from test/util.erl rename to test_etap/util.erl