pragdave / quixir

Property-based testing for Elixir
266 stars 11 forks source link

Do not force ExDoc as a compile time dependency on users. #1

Closed myronmarston closed 7 years ago

myronmarston commented 7 years ago

Without this change, I am getting a compile error:

== Compilation error on file lib/mix/tasks/update_readme.ex ==
** (CompileError) lib/mix/tasks/update_readme.ex:28: ExDoc.FunctionNode.__struct__/0 is undefined, cannot expand struct ExDoc.FunctionNode
    (stdlib) lists.erl:1353: :lists.mapfoldl/3

While it is a bit ugly to pattern match on the __struct__ key, it allows us to pattern match on the struct without requiring its definition to be present at compile time, so that users no longer need ex_doc.

vptheron commented 7 years ago

I'm getting the same error. Thanks a lot for the fix @myronmarston . Hopefully this will get merged soon.

myronmarston commented 7 years ago

@pragdave can this be merged?

pragdave commented 7 years ago

I'm not sure why this generates an error, as ex_doc is a dependency and should be available when you run update_readme. Am I missing something?

myronmarston commented 7 years ago

I'm not running update_readme. I just added quixir as a dependency to my project and tried to compile my project. I get this error. Here's an example:

https://github.com/myronmarston/quixir_issue_1

➜  quixir_issue_1 git:(master) mix deps.get && mix compile
Running dependency resolution
All dependencies up to date
==> quixir
Compiling 4 files (.ex)

== Compilation error on file lib/mix/tasks/update_readme.ex ==
** (CompileError) lib/mix/tasks/update_readme.ex:28: ExDoc.FunctionNode.__struct__/0 is undefined, cannot expand struct ExDoc.FunctionNode
    (stdlib) lists.erl:1353: :lists.mapfoldl/3

could not compile dependency :quixir, "mix compile" failed. You can recompile this dependency with "mix deps.compile quixir", update it with "mix deps.update quixir" or clean it with "mix deps.clean quixir"

I think the problem is that mix compiles all *.ex files in your project's lib directory when I have quixir as a dependency, so update_readme.ex is compiled but requires a struct definition that is not available since I don't have ex_doc in my project.

pragdave commented 7 years ago

That's a great explanation. Let me see if there's an alternative.

On Fri, Dec 2, 2016 at 9:59 PM, Myron Marston notifications@github.com wrote:

I'm not running update_readme. I just added quixir as a dependency to my project and tried to compile my project. I get this error. Here's an example:

https://github.com/myronmarston/quixir_issue_1

➜ quixir_issue_1 git:(master) mix deps.get && mix compile Running dependency resolution All dependencies up to date ==> quixir Compiling 4 files (.ex)

== Compilation error on file lib/mix/tasks/update_readme.ex == ** (CompileError) lib/mix/tasks/update_readme.ex:28: ExDoc.FunctionNode.struct/0 is undefined, cannot expand struct ExDoc.FunctionNode (stdlib) lists.erl:1353: :lists.mapfoldl/3

could not compile dependency :quixir, "mix compile" failed. You can recompile this dependency with "mix deps.compile quixir", update it with "mix deps.update quixir" or clean it with "mix deps.clean quixir"

I think the problem is that mix compiles all *.ex files in your project's lib directory when I have quixir as a dependency, so update_readme.ex is compiled but requires a struct definition that is not available since I don't have ex_doc in my project.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pragdave/quixir/pull/1#issuecomment-264614583, or mute the thread https://github.com/notifications/unsubscribe-auth/AAApmKvLDV1j5rGPCvFEu1zE0li3pS5lks5rEOk9gaJpZM4K_4Ti .

pragdave commented 7 years ago

I just pushed 0.9.1, with basic tracing, shrinking doc, and (hopefully) a fix to the ExDoc dependency. Please let me know if it works for you.

myronmarston commented 7 years ago

It does indeed work, although I don't understand how. You wrapped the entire task definition in a unless Mix.env == :prod conditional, but when I'm compiling I'm not setting MIX_ENV=prod. Does mix set Mix.env to prod when compiling dependencies, even if the host project's Mix.env is :dev or :test?

Also, your 0.9.1 release appears to include both a update_readme.ex file and a #update_readme.ex# file:

➜  quixir_issue_1 git:(master) ✗ tree deps/quixir
deps/quixir
├── CHANGELOG.md
├── README.md
├── lib
│   ├── mix
│   │   └── tasks
│   │       ├── #update_readme.ex#
│   │       └── update_readme.ex
│   ├── quixir
│   │   ├── props.ex
│   │   └── shrinker.ex
│   └── quixir.ex
└── mix.exs

4 directories, 8 files