Permalink
Browse files

Merge pull request #11 from khia/extras

Extras
  • Loading branch information...
2 parents 85fc66c + c0c3ba3 commit 1a37f862edba8a8bec342ae4945fac623f2e49ab @yrashk committed Feb 28, 2013
Showing with 50 additions and 1 deletion.
  1. +50 −1 lib/ct.ex
View
@@ -7,12 +7,61 @@ defmodule CommonTest do
def run(options) do
:ct.run_test(Keyword.put options, :auto_compile, false)
end
+
+ def run(path, options) when is_binary(path), do: run([path], options)
+ def run(paths, options) do
+ files = scan(paths)
+ run(files, options, [])
+ end
+
+ defp run([], _options, acc), do: acc
+ defp run([file_path|rest], options, acc) do
+ res = test_file(file_path, options)
+ run(rest, options, res ++ acc)
+ end
+
+ def test_file(file_path, options) do
+ suites = lc mod inlist extract_modules(file_path), is_test?(mod), do: mod
+ case suites do
+ [] -> []
+ suites ->
+ options = Keyword.merge options, [suite: suites]
+ [run(options)]
+ end
+ end
+
+ def scan(paths) do
+ files =
+ List.concat(
+ lc path inlist paths do
+ if File.regular?(path) do
+ [path]
+ else
+ Path.wildcard("#{path}/**/*.exs")
+ end
+ end)
+ files |> filter |> Enum.uniq
+ end
+
+ def filter(files) do
+ Enum.filter(files, fn(x) -> String.first(Path.basename(x)) != "." end)
+ end
+
+ def extract_modules(file_path) do
+ lc {m, _} inlist :elixir_compiler.file(file_path), do: m
+ end
+
+ def is_test?(module) do
+ Keyword.has_key?(module.__info__(:attributes), :common_test)
+ end
end
defmodule CommonTest.Suite do
defmacro __using__(_) do
quote do
import CommonTest.Suite
+ Module.register_attribute unquote(__CALLER__.module), :common_test
+ @common_test true
def suite, do: []
@@ -107,7 +156,7 @@ defmodule CommonTest.Suite do
defp _test(name, options, caller) do
name = name_to_atom(name)
- cfg = options[:config] || {:_, 0, :quoted}
+ cfg = options[:config] || {:_, [], :quoted}
info = Keyword.delete(Keyword.delete(options, :config), :do)
quote do
if Module.get_attribute(unquote(caller.module), :group) == nil do

0 comments on commit 1a37f86

Please sign in to comment.