Skip to content

Commit

Permalink
Implement use as a very simply hook mechanism.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 29, 2011
1 parent e27d86a commit 1dd9d9a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This document simply outlines the release process:

## Places where version is mentioned

* ebin/elixir.app
* src/elixir.app.src
* lib/code.ex
* README
* CHANGELOG
14 changes: 6 additions & 8 deletions lib/ex_unit/case.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module ExUnit::Case

defmacro prepare(opts // []) do
sync = Orddict.fetch(opts, :sync, false)
defmacro __using__(module, opts // []) do
if Orddict.fetch(opts, :sync, false) do
ExUnit::Server.add_sync_case(module)
else:
ExUnit::Server.add_case(module)
end

quote do
if unquote(sync) do
ExUnit::Server.add_sync_case(__MODULE__)
else:
ExUnit::Server.add_case(__MODULE__)
end

def __tests__ do
ExUnit::Case.tests_for(__MODULE__)
end
Expand Down
9 changes: 9 additions & 0 deletions src/elixir_translator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ translate_each({'{}', Line, Args}, S) when is_list(Args) ->

%% Modules

translate_each({use, Line, [Ref|Args]}, S) ->
case S#elixir_scope.module of
{0,nil} ->
elixir_errors:syntax_error(Line, S#elixir_scope.filename, "invalid scope for: ", "use");
{_,Module} ->
Call = { { '.', Line, [Ref, '__using__'] }, Line, [Module|Args] },
translate_each(Call, S)
end;

translate_each({module, Line, [Ref|Tail]}, S) ->
case S#elixir_scope.function of
[] ->
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/assertion_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module AssertionTest

ExUnit::Case.prepare
use ExUnit::Case

def test_always_pass do
true = true
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/elixir/errors_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module __MODULE__ :: UnproperMacro do
defmacro unproper(args), do: args
end

ExUnit::Case.prepare
use ExUnit::Case

def test_invalid_token do
"nofile:1: invalid token: \end" = format_catch '\end'
Expand Down

0 comments on commit 1dd9d9a

Please sign in to comment.