PT-163063316 Interface to sophia #500
@ -28,13 +28,15 @@ simple_compile_test_() ->
|
|||||||
end} || ContractName <- compilable_contracts() ] ++
|
end} || ContractName <- compilable_contracts() ] ++
|
||||||
[ {"Testing error messages of " ++ ContractName,
|
[ {"Testing error messages of " ++ ContractName,
|
||||||
fun() ->
|
fun() ->
|
||||||
{type_errors, Errors} = compile(ContractName),
|
<<"Type errors\n",ErrorString/binary>> = compile(ContractName),
|
||||||
check_errors(lists:sort(ExpectedErrors), lists:sort(Errors))
|
check_errors(lists:sort(ExpectedErrors), ErrorString)
|
||||||
end} ||
|
end} ||
|
||||||
{ContractName, ExpectedErrors} <- failing_contracts() ]
|
{ContractName, ExpectedErrors} <- failing_contracts() ]
|
||||||
}.
|
}.
|
||||||
|
|
||||||
check_errors(Expect, Actual) ->
|
check_errors(Expect, ErrorString) ->
|
||||||
|
%% This removes the final single \n as well.
|
||||||
|
Actual = binary:split(<<ErrorString/binary,$\n>>, <<"\n\n">>, [global,trim]),
|
||||||
case {Expect -- Actual, Actual -- Expect} of
|
case {Expect -- Actual, Actual -- Expect} of
|
||||||
{[], Extra} -> ?assertMatch({unexpected, []}, {unexpected, Extra});
|
{[], Extra} -> ?assertMatch({unexpected, []}, {unexpected, Extra});
|
||||||
{Missing, []} -> ?assertMatch({missing, []}, {missing, Missing});
|
{Missing, []} -> ?assertMatch({missing, []}, {missing, Missing});
|
||||||
@ -42,10 +44,10 @@ check_errors(Expect, Actual) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
compile(Name) ->
|
compile(Name) ->
|
||||||
try
|
String = aeso_test_utils:read_contract(Name),
|
||||||
aeso_compiler:from_string(aeso_test_utils:read_contract(Name), [])
|
case aeso_compiler:from_string(String, []) of
|
||||||
catch _:{type_errors, _} = E ->
|
{ok,Map} -> Map;
|
||||||
E
|
{error,ErrorString} -> ErrorString
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% compilable_contracts() -> [ContractName].
|
%% compilable_contracts() -> [ContractName].
|
||||||
@ -75,82 +77,94 @@ compilable_contracts() ->
|
|||||||
|
|
||||||
failing_contracts() ->
|
failing_contracts() ->
|
||||||
[ {"name_clash",
|
[ {"name_clash",
|
||||||
["Duplicate definitions of abort at\n - (builtin location)\n - line 14, column 3\n",
|
[<<"Duplicate definitions of abort at\n"
|
||||||
"Duplicate definitions of double_def at\n - line 10, column 3\n - line 11, column 3\n",
|
" - (builtin location)\n"
|
||||||
"Duplicate definitions of double_proto at\n - line 4, column 3\n - line 5, column 3\n",
|
" - line 14, column 3">>,
|
||||||
"Duplicate definitions of proto_and_def at\n - line 7, column 3\n - line 8, column 3\n",
|
<<"Duplicate definitions of double_def at\n"
|
||||||
"Duplicate definitions of put at\n - (builtin location)\n - line 15, column 3\n",
|
" - line 10, column 3\n"
|
||||||
"Duplicate definitions of state at\n - (builtin location)\n - line 16, column 3\n"]}
|
" - line 11, column 3">>,
|
||||||
|
<<"Duplicate definitions of double_proto at\n"
|
||||||
|
" - line 4, column 3\n"
|
||||||
|
" - line 5, column 3">>,
|
||||||
|
<<"Duplicate definitions of proto_and_def at\n"
|
||||||
|
" - line 7, column 3\n"
|
||||||
|
" - line 8, column 3">>,
|
||||||
|
<<"Duplicate definitions of put at\n"
|
||||||
|
" - (builtin location)\n"
|
||||||
|
" - line 15, column 3">>,
|
||||||
|
<<"Duplicate definitions of state at\n"
|
||||||
|
" - (builtin location)\n"
|
||||||
|
" - line 16, column 3">>]}
|
||||||
, {"type_errors",
|
, {"type_errors",
|
||||||
["Unbound variable zz at line 17, column 21\n",
|
[<<"Unbound variable zz at line 17, column 21">>,
|
||||||
"Cannot unify int\n"
|
<<"Cannot unify int\n"
|
||||||
" and list(int)\n"
|
" and list(int)\n"
|
||||||
"when checking the application at line 26, column 9 of\n"
|
"when checking the application at line 26, column 9 of\n"
|
||||||
" (::) : (int, list(int)) => list(int)\n"
|
" (::) : (int, list(int)) => list(int)\n"
|
||||||
"to arguments\n"
|
"to arguments\n"
|
||||||
" x : int\n"
|
" x : int\n"
|
||||||
" x : int\n",
|
" x : int">>,
|
||||||
"Cannot unify string\n"
|
<<"Cannot unify string\n"
|
||||||
" and int\n"
|
" and int\n"
|
||||||
"when checking the assignment of the field\n"
|
"when checking the assignment of the field\n"
|
||||||
" x : map(string, string) (at line 9, column 46)\n"
|
" x : map(string, string) (at line 9, column 46)\n"
|
||||||
"to the old value __x and the new value\n"
|
"to the old value __x and the new value\n"
|
||||||
" __x {[\"foo\"] @ x = x + 1} : map(string, int)\n",
|
" __x {[\"foo\"] @ x = x + 1} : map(string, int)">>,
|
||||||
"Cannot unify int\n"
|
<<"Cannot unify int\n"
|
||||||
" and string\n"
|
" and string\n"
|
||||||
"when checking the type of the expression at line 34, column 45\n"
|
"when checking the type of the expression at line 34, column 45\n"
|
||||||
" 1 : int\n"
|
" 1 : int\n"
|
||||||
"against the expected type\n"
|
"against the expected type\n"
|
||||||
" string\n",
|
" string">>,
|
||||||
"Cannot unify string\n"
|
<<"Cannot unify string\n"
|
||||||
" and int\n"
|
" and int\n"
|
||||||
"when checking the type of the expression at line 34, column 50\n"
|
"when checking the type of the expression at line 34, column 50\n"
|
||||||
" \"bla\" : string\n"
|
" \"bla\" : string\n"
|
||||||
"against the expected type\n"
|
"against the expected type\n"
|
||||||
" int\n",
|
" int">>,
|
||||||
"Cannot unify string\n"
|
<<"Cannot unify string\n"
|
||||||
" and int\n"
|
" and int\n"
|
||||||
"when checking the type of the expression at line 32, column 18\n"
|
"when checking the type of the expression at line 32, column 18\n"
|
||||||
" \"x\" : string\n"
|
" \"x\" : string\n"
|
||||||
"against the expected type\n"
|
"against the expected type\n"
|
||||||
" int\n",
|
" int">>,
|
||||||
"Cannot unify string\n"
|
<<"Cannot unify string\n"
|
||||||
" and int\n"
|
" and int\n"
|
||||||
"when checking the type of the expression at line 11, column 56\n"
|
"when checking the type of the expression at line 11, column 56\n"
|
||||||
" \"foo\" : string\n"
|
" \"foo\" : string\n"
|
||||||
"against the expected type\n"
|
"against the expected type\n"
|
||||||
" int\n",
|
" int">>,
|
||||||
"Cannot unify int\n"
|
<<"Cannot unify int\n"
|
||||||
" and string\n"
|
" and string\n"
|
||||||
"when comparing the types of the if-branches\n"
|
"when comparing the types of the if-branches\n"
|
||||||
" - w : int (at line 38, column 13)\n"
|
" - w : int (at line 38, column 13)\n"
|
||||||
" - z : string (at line 39, column 10)\n",
|
" - z : string (at line 39, column 10)">>,
|
||||||
"Not a record type: string\n"
|
<<"Not a record type: string\n"
|
||||||
"arising from the projection of the field y (at line 22, column 38)\n",
|
"arising from the projection of the field y (at line 22, column 38)">>,
|
||||||
"Not a record type: string\n"
|
<<"Not a record type: string\n"
|
||||||
"arising from an assignment of the field y (at line 21, column 42)\n",
|
"arising from an assignment of the field y (at line 21, column 42)">>,
|
||||||
"Not a record type: string\n"
|
<<"Not a record type: string\n"
|
||||||
"arising from an assignment of the field y (at line 20, column 38)\n",
|
"arising from an assignment of the field y (at line 20, column 38)">>,
|
||||||
"Not a record type: string\n"
|
<<"Not a record type: string\n"
|
||||||
"arising from an assignment of the field y (at line 19, column 35)\n",
|
"arising from an assignment of the field y (at line 19, column 35)">>,
|
||||||
"Ambiguous record type with field y (at line 13, column 25) could be one of\n"
|
<<"Ambiguous record type with field y (at line 13, column 25) could be one of\n"
|
||||||
" - r (at line 4, column 10)\n"
|
" - r (at line 4, column 10)\n"
|
||||||
" - r' (at line 5, column 10)\n",
|
" - r' (at line 5, column 10)">>,
|
||||||
"Record type r2 does not have field y (at line 15, column 22)\n",
|
<<"Record type r2 does not have field y (at line 15, column 22)">>,
|
||||||
"The field z is missing when constructing an element of type r2 (at line 15, column 24)\n",
|
<<"The field z is missing when constructing an element of type r2 (at line 15, column 24)">>,
|
||||||
"Repeated name x in pattern\n"
|
<<"Repeated name x in pattern\n"
|
||||||
" x :: x (at line 26, column 7)\n",
|
" x :: x (at line 26, column 7)">>,
|
||||||
"No record type with fields y, z (at line 14, column 22)\n"]}
|
<<"No record type with fields y, z (at line 14, column 22)">>]}
|
||||||
, {"init_type_error",
|
, {"init_type_error",
|
||||||
["Cannot unify string\n"
|
[<<"Cannot unify string\n"
|
||||||
" and map(int, int)\n"
|
" and map(int, int)\n"
|
||||||
"when checking that 'init' returns a value of type 'state' at line 7, column 3\n"]}
|
"when checking that 'init' returns a value of type 'state' at line 7, column 3">>]}
|
||||||
, {"missing_state_type",
|
, {"missing_state_type",
|
||||||
["Cannot unify string\n"
|
[<<"Cannot unify string\n"
|
||||||
" and ()\n"
|
" and ()\n"
|
||||||
"when checking that 'init' returns a value of type 'state' at line 5, column 3\n"]}
|
"when checking that 'init' returns a value of type 'state' at line 5, column 3">>]}
|
||||||
, {"missing_fields_in_record_expression",
|
, {"missing_fields_in_record_expression",
|
||||||
["The field x is missing when constructing an element of type r('a) (at line 7, column 40)\n",
|
[<<"The field x is missing when constructing an element of type r('a) (at line 7, column 40)">>,
|
||||||
"The field y is missing when constructing an element of type r(int) (at line 8, column 40)\n",
|
<<"The field y is missing when constructing an element of type r(int) (at line 8, column 40)">>,
|
||||||
"The fields y, z are missing when constructing an element of type r('1) (at line 6, column 40)\n"]}
|
<<"The fields y, z are missing when constructing an element of type r('1) (at line 6, column 40)">>]}
|
||||||
].
|
].
|
||||||
|
Loading…
x
Reference in New Issue
Block a user