diff --git a/.gitignore b/.gitignore index cc0e3da8..6c1ef4ff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ deps *.o *.beam +*.erltypes *.plt /.dialyzer_plt *~ diff --git a/Makefile b/Makefile index 0eddb11c..34a8b53d 100644 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ clean: rm -rf bin/gradualizer ebin cover test/*.beam .PHONY: tests eunit compile-tests cli-tests -tests: build_test_data eunit cli-tests +tests: check_name_clashes build_test_data eunit cli-tests test_erls=$(wildcard test/*.erl) test_beams=$(test_erls:test/%.erl=test/%.beam) @@ -212,6 +212,14 @@ DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions dialyze: app $(DIALYZER_PLT) dialyzer $(DIALYZER_OPTS) ebin +.PHONY: dialyze-tests +dialyze-tests: app $(DIALYZER_PLT) + dialyzer $(DIALYZER_OPTS) $(test_data_erls) + +.PHONY: check_name_clashes +check_name_clashes: + test/check_name_clashes.sh + # DIALYZER_PLT is a variable understood directly by Dialyzer. # Exit status 2 = warnings were emitted $(DIALYZER_PLT): diff --git a/test/check_name_clashes.sh b/test/check_name_clashes.sh new file mode 100755 index 00000000..681a1cfa --- /dev/null +++ b/test/check_name_clashes.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +#set -x + +if [ x$(uname) == x"Darwin" ]; then +BASENAME=basename +else +BASENAME="basename -a" +fi + +UNIQ=$(find test/should_pass test/should_fail test/known_problems/*/ -name \*.erl \ + | xargs $BASENAME \ + | sort \ + | uniq -c \ + | sort -n \ + | tail -1) + +COUNT=$(echo $UNIQ | awk '{print $1}') + +if [ "$COUNT" == 1 ]; then + exit 0 +else + echo "Name clash in tests:" + find test -name $(echo $UNIQ | awk '{print $2}') + exit 1 +fi diff --git a/test/known_problems/should_fail/guard_fail.erl b/test/known_problems/should_fail/guard_should_fail.erl similarity index 88% rename from test/known_problems/should_fail/guard_fail.erl rename to test/known_problems/should_fail/guard_should_fail.erl index 2d6bbc28..eb38c430 100644 --- a/test/known_problems/should_fail/guard_fail.erl +++ b/test/known_problems/should_fail/guard_should_fail.erl @@ -1,4 +1,4 @@ --module(guard_fail). +-module(guard_should_fail). -compile([export_all, nowarn_export_all]). diff --git a/test/known_problems/should_fail/intersection_with_any_fail.erl b/test/known_problems/should_fail/intersection_with_any_should_fail.erl similarity index 94% rename from test/known_problems/should_fail/intersection_with_any_fail.erl rename to test/known_problems/should_fail/intersection_with_any_should_fail.erl index 9c3cd4f5..ceab9fb6 100644 --- a/test/known_problems/should_fail/intersection_with_any_fail.erl +++ b/test/known_problems/should_fail/intersection_with_any_should_fail.erl @@ -1,4 +1,4 @@ --module(intersection_with_any_fail). +-module(intersection_with_any_should_fail). -export([any_refined_using_guard/1, var_as_pattern/1, diff --git a/test/known_problems/should_fail/rigid_type_variables.erl b/test/known_problems/should_fail/rigid_type_variables_fail.erl similarity index 69% rename from test/known_problems/should_fail/rigid_type_variables.erl rename to test/known_problems/should_fail/rigid_type_variables_fail.erl index 1e61b227..3108ba02 100644 --- a/test/known_problems/should_fail/rigid_type_variables.erl +++ b/test/known_problems/should_fail/rigid_type_variables_fail.erl @@ -1,4 +1,4 @@ --module(rigid_type_variables). +-module(rigid_type_variables_fail). -compile([export_all, nowarn_export_all]). diff --git a/test/known_problems/should_pass/rigid_type_variables.erl b/test/known_problems/should_pass/rigid_type_variables_pass.erl similarity index 81% rename from test/known_problems/should_pass/rigid_type_variables.erl rename to test/known_problems/should_pass/rigid_type_variables_pass.erl index 924ef318..ea5bc05e 100644 --- a/test/known_problems/should_pass/rigid_type_variables.erl +++ b/test/known_problems/should_pass/rigid_type_variables_pass.erl @@ -1,4 +1,4 @@ --module(rigid_type_variables). +-module(rigid_type_variables_pass). -compile([export_all, nowarn_export_all]). diff --git a/test/should_fail/arith_op.erl b/test/should_fail/arith_op_fail.erl similarity index 98% rename from test/should_fail/arith_op.erl rename to test/should_fail/arith_op_fail.erl index 9019a491..93f286de 100644 --- a/test/should_fail/arith_op.erl +++ b/test/should_fail/arith_op_fail.erl @@ -1,4 +1,5 @@ --module(arith_op). +-module(arith_op_fail). + -export([failplus/1, faildivvar/1, faildivlit/1, failpositivedivision/1, faildivprecise/1, failplusprecise/2, failminusprecisepos/2, failminusnonneg/2, failminuspreciseneg/2, diff --git a/test/should_fail/bc.erl b/test/should_fail/bc_fail.erl similarity index 94% rename from test/should_fail/bc.erl rename to test/should_fail/bc_fail.erl index b46ce780..62f73094 100644 --- a/test/should_fail/bc.erl +++ b/test/should_fail/bc_fail.erl @@ -1,4 +1,4 @@ --module(bc). +-module(bc_fail). -export([f/0, non_bin_expr/0, integer_signed_wrong/1]). -spec f() -> binary(). diff --git a/test/should_fail/catch_expr.erl b/test/should_fail/catch_expr_fail.erl similarity index 75% rename from test/should_fail/catch_expr.erl rename to test/should_fail/catch_expr_fail.erl index d7f32060..7db7d304 100644 --- a/test/should_fail/catch_expr.erl +++ b/test/should_fail/catch_expr_fail.erl @@ -1,4 +1,4 @@ --module(catch_expr). +-module(catch_expr_fail). -export([foo/1]). diff --git a/test/should_fail/covariant_map_keys.erl b/test/should_fail/covariant_map_keys_fail.erl similarity index 89% rename from test/should_fail/covariant_map_keys.erl rename to test/should_fail/covariant_map_keys_fail.erl index 9db1770c..99c5883b 100644 --- a/test/should_fail/covariant_map_keys.erl +++ b/test/should_fail/covariant_map_keys_fail.erl @@ -1,4 +1,4 @@ --module(covariant_map_keys). +-module(covariant_map_keys_fail). -compile([nowarn_unused_function]). -export([not_good/1]). diff --git a/test/should_fail/intersection_with_any.erl b/test/should_fail/intersection_with_any_fail.erl similarity index 82% rename from test/should_fail/intersection_with_any.erl rename to test/should_fail/intersection_with_any_fail.erl index f14777c6..915dc972 100644 --- a/test/should_fail/intersection_with_any.erl +++ b/test/should_fail/intersection_with_any_fail.erl @@ -1,4 +1,4 @@ --module(intersection_with_any). +-module(intersection_with_any_fail). -export([intersection_using_constraints/1]). diff --git a/test/should_fail/list_infer.erl b/test/should_fail/list_infer_fail.erl similarity index 81% rename from test/should_fail/list_infer.erl rename to test/should_fail/list_infer_fail.erl index dc155b6c..59876421 100644 --- a/test/should_fail/list_infer.erl +++ b/test/should_fail/list_infer_fail.erl @@ -1,4 +1,4 @@ --module(list_infer). +-module(list_infer_fail). -gradualizer(infer). -export([f/0]). diff --git a/test/should_fail/messaging.erl b/test/should_fail/messaging_fail.erl similarity index 96% rename from test/should_fail/messaging.erl rename to test/should_fail/messaging_fail.erl index 9b8d276f..5016c4a5 100644 --- a/test/should_fail/messaging.erl +++ b/test/should_fail/messaging_fail.erl @@ -1,4 +1,4 @@ --module(messaging). +-module(messaging_fail). -export([server1/0, server2/0, server3/0, server4/0]). diff --git a/test/should_fail/named_fun.erl b/test/should_fail/named_fun_fail.erl similarity index 88% rename from test/should_fail/named_fun.erl rename to test/should_fail/named_fun_fail.erl index 5fab8527..17d3938b 100644 --- a/test/should_fail/named_fun.erl +++ b/test/should_fail/named_fun_fail.erl @@ -1,4 +1,4 @@ --module(named_fun). +-module(named_fun_fail). -export([bar/0, baz/1]). diff --git a/test/should_fail/named_fun_infer.erl b/test/should_fail/named_fun_infer_fail.erl similarity index 92% rename from test/should_fail/named_fun_infer.erl rename to test/should_fail/named_fun_infer_fail.erl index f4a82621..72978a15 100644 --- a/test/should_fail/named_fun_infer.erl +++ b/test/should_fail/named_fun_infer_fail.erl @@ -1,4 +1,4 @@ --module(named_fun_infer). +-module(named_fun_infer_fail). -gradualizer(infer). -export([bar/0, sum/1]). diff --git a/test/should_fail/operator_pattern.erl b/test/should_fail/operator_pattern_fail.erl similarity index 78% rename from test/should_fail/operator_pattern.erl rename to test/should_fail/operator_pattern_fail.erl index bfaded21..08f0464b 100644 --- a/test/should_fail/operator_pattern.erl +++ b/test/should_fail/operator_pattern_fail.erl @@ -1,4 +1,4 @@ --module(operator_pattern). +-module(operator_pattern_fail). -export([n/1, p/1]). -spec n(non_neg_integer()) -> {}. diff --git a/test/should_fail/record_refinement_fail.erl b/test/should_fail/record_refinement_fail.erl index 0d2b26ff..448e04ad 100644 --- a/test/should_fail/record_refinement_fail.erl +++ b/test/should_fail/record_refinement_fail.erl @@ -16,6 +16,8 @@ one_field2(_, I) -> I. -spec refined_field(#refined_field{}) -> #refined_field{f :: integer()}. refined_field(R) -> R. +%% The refinement in the result type is not handled by Dialyzer - it will error out. +%% Comment it out if trying to run `make dialyze-tests'. -spec refined_field2(#refined_field{}) -> #refined_field{f :: atom()}. refined_field2(#refined_field{f = undefined}) -> #refined_field{f = 0}; refined_field2(R) -> R. diff --git a/test/should_fail/record_wildcard.erl b/test/should_fail/record_wildcard_fail.erl similarity index 91% rename from test/should_fail/record_wildcard.erl rename to test/should_fail/record_wildcard_fail.erl index 2553f551..be0e66de 100644 --- a/test/should_fail/record_wildcard.erl +++ b/test/should_fail/record_wildcard_fail.erl @@ -1,4 +1,4 @@ --module(record_wildcard). +-module(record_wildcard_fail). -export([f/0, g/0]). diff --git a/test/should_fail/send.erl b/test/should_fail/send_fail.erl similarity index 87% rename from test/should_fail/send.erl rename to test/should_fail/send_fail.erl index 75cd7a4c..aa5420a6 100644 --- a/test/should_fail/send.erl +++ b/test/should_fail/send_fail.erl @@ -1,4 +1,4 @@ --module(send). +-module(send_fail). -export([foo/2, bar/2]). diff --git a/test/should_fail/shortcut_ops.erl b/test/should_fail/shortcut_ops_fail.erl similarity index 94% rename from test/should_fail/shortcut_ops.erl rename to test/should_fail/shortcut_ops_fail.erl index 8e1b317b..d5b8d4f8 100644 --- a/test/should_fail/shortcut_ops.erl +++ b/test/should_fail/shortcut_ops_fail.erl @@ -1,4 +1,4 @@ --module(shortcut_ops). +-module(shortcut_ops_fail). -compile([export_all, nowarn_export_all]). diff --git a/test/should_fail/tuple_union.erl b/test/should_fail/tuple_union.erl deleted file mode 100644 index b3aadfb6..00000000 --- a/test/should_fail/tuple_union.erl +++ /dev/null @@ -1,7 +0,0 @@ --module(tuple_union). - --export([tuple_union/0]). - --spec tuple_union() -> {undefined, binary()} | {integer(), undefined}. -tuple_union() -> - {undefined, undefined}. diff --git a/test/should_fail/tuple_union_fail.erl b/test/should_fail/tuple_union_fail.erl index 91601e17..a510e3ff 100644 --- a/test/should_fail/tuple_union_fail.erl +++ b/test/should_fail/tuple_union_fail.erl @@ -1,7 +1,12 @@ -module(tuple_union_fail). -export([f/0]). +-export([tuple_union/0]). -spec f() -> {integer()} | {boolean()}. f() -> {apa}. + +-spec tuple_union() -> {undefined, binary()} | {integer(), undefined}. +tuple_union() -> + {undefined, undefined}. diff --git a/test/should_fail/type_refinement.erl b/test/should_fail/type_refinement_fail.erl similarity index 97% rename from test/should_fail/type_refinement.erl rename to test/should_fail/type_refinement_fail.erl index d6cf0f57..cb83c751 100644 --- a/test/should_fail/type_refinement.erl +++ b/test/should_fail/type_refinement_fail.erl @@ -1,4 +1,4 @@ --module(type_refinement). +-module(type_refinement_fail). -export([guard_prevents_refinement/2, imprecision_prevents_refinement/2, multi_pat_fail_1/2, guard_prevents_refinement2/1, diff --git a/test/should_pass/bc.erl b/test/should_pass/bc_pass.erl similarity index 99% rename from test/should_pass/bc.erl rename to test/should_pass/bc_pass.erl index dda34365..dc5389ab 100644 --- a/test/should_pass/bc.erl +++ b/test/should_pass/bc_pass.erl @@ -1,4 +1,4 @@ --module(bc). +-module(bc_pass). -compile([export_all, nowarn_export_all]). diff --git a/test/should_pass/catch_expr.erl b/test/should_pass/catch_expr_pass.erl similarity index 74% rename from test/should_pass/catch_expr.erl rename to test/should_pass/catch_expr_pass.erl index 97b64324..b07c0536 100644 --- a/test/should_pass/catch_expr.erl +++ b/test/should_pass/catch_expr_pass.erl @@ -1,4 +1,4 @@ --module(catch_expr). +-module(catch_expr_pass). -export([foo/1]). diff --git a/test/should_pass/covariant_map_keys.erl b/test/should_pass/covariant_map_keys_pass.erl similarity index 81% rename from test/should_pass/covariant_map_keys.erl rename to test/should_pass/covariant_map_keys_pass.erl index c2ccf4b4..352c63d1 100644 --- a/test/should_pass/covariant_map_keys.erl +++ b/test/should_pass/covariant_map_keys_pass.erl @@ -1,4 +1,4 @@ --module(covariant_map_keys). +-module(covariant_map_keys_pass). -compile([export_all, nowarn_export_all]). diff --git a/test/should_pass/intersection.erl b/test/should_pass/intersection_pass.erl similarity index 87% rename from test/should_pass/intersection.erl rename to test/should_pass/intersection_pass.erl index d00a2d03..be36aae7 100644 --- a/test/should_pass/intersection.erl +++ b/test/should_pass/intersection_pass.erl @@ -1,4 +1,4 @@ --module(intersection). +-module(intersection_pass). -compile([export_all, nowarn_export_all]). diff --git a/test/should_pass/intersection_with_any.erl b/test/should_pass/intersection_with_any_pass.erl similarity index 94% rename from test/should_pass/intersection_with_any.erl rename to test/should_pass/intersection_with_any_pass.erl index b1d1b654..4084ddc6 100644 --- a/test/should_pass/intersection_with_any.erl +++ b/test/should_pass/intersection_with_any_pass.erl @@ -1,4 +1,4 @@ --module(intersection_with_any). +-module(intersection_with_any_pass). -compile([export_all, nowarn_export_all]). diff --git a/test/should_pass/list_infer.erl b/test/should_pass/list_infer_pass.erl similarity index 85% rename from test/should_pass/list_infer.erl rename to test/should_pass/list_infer_pass.erl index afb89ba4..04095da2 100644 --- a/test/should_pass/list_infer.erl +++ b/test/should_pass/list_infer_pass.erl @@ -1,4 +1,4 @@ --module(list_infer). +-module(list_infer_pass). -gradualizer(infer). -export([f/0]). diff --git a/test/should_pass/messaging.erl b/test/should_pass/messaging_pass.erl similarity index 97% rename from test/should_pass/messaging.erl rename to test/should_pass/messaging_pass.erl index 1a315662..44fa4990 100644 --- a/test/should_pass/messaging.erl +++ b/test/should_pass/messaging_pass.erl @@ -1,4 +1,4 @@ --module(messaging). +-module(messaging_pass). -export([main/0, server/0, server1/0, server2/0, server3/0, server4/0]). diff --git a/test/should_pass/named_fun_infer.erl b/test/should_pass/named_fun_infer_pass.erl similarity index 92% rename from test/should_pass/named_fun_infer.erl rename to test/should_pass/named_fun_infer_pass.erl index 87b4798d..ac4dd10c 100644 --- a/test/should_pass/named_fun_infer.erl +++ b/test/should_pass/named_fun_infer_pass.erl @@ -1,4 +1,4 @@ --module(named_fun_infer). +-module(named_fun_infer_pass). -gradualizer(infer). -export([atom_sum/1]). diff --git a/test/should_pass/named_fun.erl b/test/should_pass/named_fun_pass.erl similarity index 95% rename from test/should_pass/named_fun.erl rename to test/should_pass/named_fun_pass.erl index f11a632d..7ad911d6 100644 --- a/test/should_pass/named_fun.erl +++ b/test/should_pass/named_fun_pass.erl @@ -1,4 +1,4 @@ --module(named_fun). +-module(named_fun_pass). -export([fac/1, sum/1]). diff --git a/test/should_pass/operator_pattern.erl b/test/should_pass/operator_pattern_pass.erl similarity index 97% rename from test/should_pass/operator_pattern.erl rename to test/should_pass/operator_pattern_pass.erl index 60bf25c8..f4bc3dd3 100644 --- a/test/should_pass/operator_pattern.erl +++ b/test/should_pass/operator_pattern_pass.erl @@ -1,4 +1,4 @@ --module(operator_pattern). +-module(operator_pattern_pass). -compile([export_all, nowarn_export_all]). diff --git a/test/should_pass/record_wildcard.erl b/test/should_pass/record_wildcard_pass.erl similarity index 93% rename from test/should_pass/record_wildcard.erl rename to test/should_pass/record_wildcard_pass.erl index 0177be00..c54aea5e 100644 --- a/test/should_pass/record_wildcard.erl +++ b/test/should_pass/record_wildcard_pass.erl @@ -1,4 +1,4 @@ --module(record_wildcard). +-module(record_wildcard_pass). -export([f/0, g/0, h/1]). diff --git a/test/should_pass/records.erl b/test/should_pass/records.erl index da736595..3916d926 100644 --- a/test/should_pass/records.erl +++ b/test/should_pass/records.erl @@ -1,9 +1,10 @@ -module(records). --export([f/0, g/1, h/0, i/0, j/0, k/0, l/0, +-export([f/0, f/1, g/1, h/0, i/0, j/0, k/0, l/0, rec_field_subtype/1, rec_index_subtype/0, - record_as_tuple/1]). + record_as_tuple/1, + nospec_update_bug/1]). -record(r, {f1 :: atom(), f2 = 1 :: integer()}). diff --git a/test/should_pass/send.erl b/test/should_pass/send_pass.erl similarity index 87% rename from test/should_pass/send.erl rename to test/should_pass/send_pass.erl index d0671634..2bf450cb 100644 --- a/test/should_pass/send.erl +++ b/test/should_pass/send_pass.erl @@ -1,4 +1,4 @@ --module(send). +-module(send_pass). -export([foo/2, bar/2]). diff --git a/test/should_pass/shortcut_ops.erl b/test/should_pass/shortcut_ops_pass.erl similarity index 98% rename from test/should_pass/shortcut_ops.erl rename to test/should_pass/shortcut_ops_pass.erl index 426bcb89..1d5dcd02 100644 --- a/test/should_pass/shortcut_ops.erl +++ b/test/should_pass/shortcut_ops_pass.erl @@ -1,4 +1,4 @@ --module(shortcut_ops). +-module(shortcut_ops_pass). -compile([export_all, nowarn_export_all]). diff --git a/test/should_pass/tuple_union.erl b/test/should_pass/tuple_union_pass.erl similarity index 74% rename from test/should_pass/tuple_union.erl rename to test/should_pass/tuple_union_pass.erl index 74693dea..32465eaa 100644 --- a/test/should_pass/tuple_union.erl +++ b/test/should_pass/tuple_union_pass.erl @@ -1,4 +1,4 @@ --module(tuple_union). +-module(tuple_union_pass). -export([f/0]). diff --git a/test/should_pass/type_refinement.erl b/test/should_pass/type_refinement_pass.erl similarity index 98% rename from test/should_pass/type_refinement.erl rename to test/should_pass/type_refinement_pass.erl index 83cb578d..c8341709 100644 --- a/test/should_pass/type_refinement.erl +++ b/test/should_pass/type_refinement_pass.erl @@ -1,4 +1,4 @@ --module(type_refinement). +-module(type_refinement_pass). -compile([export_all, nowarn_export_all]).