josephwilk / amrita

A polite, well mannered and thoroughly upstanding testing framework for Elixir
201 stars 28 forks source link

[FYI] solution without brackets #117

Open ritalin opened 10 years ago

ritalin commented 10 years ago

in test/integration/t_checkers.exs,

latest source is:

     fact "supports ! and positive form" do
       1000 |> thousand()
       1001 |> ! thousand()

       fail do
         1001 |> thousand()
         1000 |> ! thousand()
       end
     end

I've found solution without brackets.

In lib/amrita/elixir/pipline.ex, fix such as the following.

  defp pipeline_op(left, { call, line, atom }) when is_atom(atom) do
    quote do
      local_var_value = binding[unquote(call)]
      if local_var_value do
        unquote(left) |> Amrita.Checkers.Simple.equals local_var_value
      else
        if is_nil(unquote(atom)) and Keyword.has_key?(__MODULE__.module_info[:exports], unquote(call)) do
          apply(__MODULE__, unquote(call), [unquote(left)])
        else
          Code.eval_quoted({unquote(call), unquote(line), [unquote(left)]},
                         binding,
                         __ENV__)
        end
      end
    end
  end

When call thousand function, atom argument was nil. Therefore, failed to evaluate as function.

This code is: If right hand term is exported as function, call it directory.

But It may be fail if right hand term is a local variable with same name exporting function….