Permalink
Browse files

Handle column numbers in ms_transform test suite

  • Loading branch information...
1 parent ee971e6 commit e4120f4517a596f284d32ce0d20c9baa7d9596e3 @nox nox committed Aug 26, 2012
Showing with 61 additions and 62 deletions.
  1. +61 −62 lib/stdlib/test/ms_transform_SUITE.erl
@@ -83,76 +83,74 @@ warnings(doc) ->
["Check that shadowed variables in fun head generate warning"];
warnings(Config) when is_list(Config) ->
?line setup(Config),
- Prog = <<"A=5, "
- "ets:fun2ms(fun({A,B}) "
- " when is_integer(A) and (A+5 > B) -> "
- " A andalso B "
- " end)">>,
- ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}]}] =
+ Prog = <<"A=5,
+ ets:fun2ms(fun ({A,B}) when is_integer(A) and (A+5 > B) ->
+ A andalso B
+ end)">>,
+ ?line [{_,[{{2,32},ms_transform,{?WARN_NUMBER_SHADOW,'A'}}]}] =
compile_ww(Prog),
- Prog2 = <<"C=5, "
- "ets:fun2ms(fun({A,B} = C) "
- " when is_integer(A) and (A+5 > B) -> "
- " {A andalso B,C} "
- " end)">>,
- ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
+ Prog2 = <<"C=5,
+ ets:fun2ms(fun ({A,B} = C) when is_integer(A) and (A+5 > B) ->
+ {A andalso B,C}
+ end)">>,
+ ?line [{_,[{{2,40},ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
compile_ww(Prog2),
Rec3 = <<"-record(a,{a,b,c,d=foppa}).">>,
- Prog3 = <<"A=3,C=5, "
- "ets:fun2ms(fun(#a{a = A, b = B} = C) "
- " when is_integer(A) and (A+5 > B) -> "
- " {A andalso B,C} "
- " end)">>,
- ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}},
- {_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
+ Prog3 = <<"A=3,C=5,
+ ets:fun2ms(fun (#a{a = A, b = B} = C)
+ when is_integer(A) and (A+5 > B) ->
+ {A andalso B,C}
+ end)">>,
+ ?line [{_,[{{2,39},ms_transform,{?WARN_NUMBER_SHADOW,'A'}},
+ {{2,51},ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
compile_ww(Rec3,Prog3),
Rec4 = <<"-record(a,{a,b,c,d=foppa}).">>,
- Prog4 = <<"A=3,C=5, "
- "F = fun(B) -> B*3 end,"
- "erlang:display(F(A)),"
- "ets:fun2ms(fun(#a{a = A, b = B} = C) "
- " when is_integer(A) and (A+5 > B) -> "
- " {A andalso B,C} "
- " end)">>,
- ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}},
- {_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
+ Prog4 = <<"A=3,C=5,
+ F = fun(B) -> B*3 end,
+ erlang:display(F(A)),
+ ets:fun2ms(fun (#a{a = A, b = B} = C)
+ when is_integer(A) and (A+5 > B) ->
+ {A andalso B,C}
+ end)">>,
+ ?line [{_,[{{4,39},ms_transform,{?WARN_NUMBER_SHADOW,'A'}},
+ {{4,51},ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
compile_ww(Rec4,Prog4),
Rec5 = <<"-record(a,{a,b,c,d=foppa}).">>,
- Prog5 = <<"A=3,C=5, "
- "F = fun(B) -> B*3 end,"
- "erlang:display(F(A)),"
- "B = ets:fun2ms(fun(#a{a = A, b = B} = C) "
- " when is_integer(A) and (A+5 > B) -> "
- " {A andalso B,C} "
- " end)">>,
- ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}},
- {_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
+ Prog5 = <<"A=3,C=5,
+ F = fun(B) -> B*3 end,
+ erlang:display(F(A)),
+ B = ets:fun2ms(fun (#a{a = A, b = B} = C)
+ when is_integer(A) and (A+5 > B) ->
+ {A andalso B,C}
+ end)">>,
+ ?line [{_,[{{4,43},ms_transform,{?WARN_NUMBER_SHADOW,'A'}},
+ {{4,55},ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] =
compile_ww(Rec5,Prog5),
- Prog6 = <<" X=bar, "
- " A = case X of"
- " foo ->"
- " foo;"
- " Y ->"
- " ets:fun2ms(fun(Y) ->" % This is a warning
- " 3*Y"
- " end)"
- " end,"
- " ets:fun2ms(fun(Y) ->" % Y out of "scope" here, so no warning
- " {3*Y,A}"
- " end)">>,
- ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] =
+ Prog6 = <<"X=bar,
+ A = case X of
+ foo ->
+ foo;
+ Y ->
+ ets:fun2ms(fun (Y) -> % This is a warning
+ 3*Y
+ end)
+ end,
+ ets:fun2ms(fun (Y) -> % Y out of 'scope' here, so no warning
+ {3*Y,A}
+ end)">>,
+ ?line [{_,[{{6,44},ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] =
compile_ww(Prog6),
- Prog7 = <<" X=bar, "
- " A = case X of"
- " foo ->"
- " Y = foo;"
- " Y ->"
- " bar"
- " end,"
- " ets:fun2ms(fun(Y) ->" % Y exported from case and safe, so warn
- " {3*Y,A}"
- " end)">>,
- ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] =
+ Prog7 = <<"X=bar,
+ A = case X of
+ foo ->
+ Y = foo;
+ Y ->
+ bar
+ end,
+ ets:fun2ms(fun (Y) -> % Y exported from case and safe, so warn
+ {3*Y,A}
+ end)">>,
+ ?line [{_,[{{8,32},ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] =
compile_ww(Prog7),
ok.
@@ -858,11 +856,12 @@ compile_ww(Records,Expr) ->
"-include_lib(\"stdlib/include/ms_transform.hrl\").\n",
"-export([tmp/0]).\n",
Records/binary,"\n",
+ "-file(?FILE, 0). "
"tmp() ->\n",
Expr/binary,".\n">>,
FN=temp_name(),
file:write_file(FN,Prog),
- {ok,Forms} = epp:parse_file(FN,"",""),
+ {ok,Forms} = epp:parse_file(FN,{1,1},"",""),
{ok,tmp,_Bin,Wlist} = compile:forms(Forms,[return_warnings,
nowarn_unused_vars,
nowarn_unused_record]),

0 comments on commit e4120f4

Please sign in to comment.