Permalink
Browse files

Implement use as a very simply hook mechanism.

  • Loading branch information...
1 parent e27d86a commit 1dd9d9a498471e7ac110fe194fea2a2582a24f56 @josevalim josevalim committed Dec 29, 2011
Showing with 18 additions and 11 deletions.
  1. +1 −1 RELEASE.md
  2. +6 −8 lib/ex_unit/case.ex
  3. +9 −0 src/elixir_translator.erl
  4. +1 −1 test/elixir/assertion_test.exs
  5. +1 −1 test/elixir/elixir/errors_test.exs
View
@@ -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
View
@@ -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
@@ -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
[] ->
@@ -1,6 +1,6 @@
module AssertionTest
-ExUnit::Case.prepare
+use ExUnit::Case
def test_always_pass do
true = true
@@ -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'

0 comments on commit 1dd9d9a

Please sign in to comment.