Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created April 16, 2013 04:22
Show Gist options
  • Save pragdave/5393324 to your computer and use it in GitHub Desktop.
Save pragdave/5393324 to your computer and use it in GitHub Desktop.
defmodule Mix.Tasks.Doctest do
use Mix.Task
@shortdoc "Run the doctests for one or more files"
# Just for testing....
defmodule Wombat do
@moduledoc """
iex> 1
1
iex> 2
5
"""
end
def run(args) do
# { opts, files } = OptionParser.parse(args)
:application.start(:elixir)
:application.start(:ex_unit)
test_methods = Enum.map ExUnit.DocTest.__doctests__(Wombat, []), fn { name, test } ->
{:def,[],[{name,[],[[do: [{:_,[],nil}]]]},[do: test]]}
end
body = [{:use,[],[{:__aliases__,[],[:ExUnit,:Case]},[async: true]]} | test_methods ]
mod = {:defmodule,[],[{:__aliases__,[],[:Mix, :Tasks, :Doctest, :InternalTests]},
[do: {:__block__,[], body}]]}
Code.eval_quoted(mod)
ExUnit.configure([])
ExUnit.run
end
end
@josevalim
Copy link

The failure you are getting is probably coming from this on line 22: [[do: [{:_,[],nil}]]. It basically says your function is defined like: def name(do: _), do: test, you probably want this instead: {:def,[],[{name,[],[{:_,[],nil}]},[do: test]]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment