Skip to content

Commit a72fdb2

Browse files
committed
Merge branch 'master' of github.com:ExpressApp/construct
2 parents 0fd8ef5 + 7a563da commit a72fdb2

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ sudo: false
55

66
matrix:
77
include:
8+
- elixir: 1.9.1
9+
otp_release: 22.0.7
10+
- elixir: 1.8.2
11+
otp_release: 21.3.8
812
- elixir: 1.7.2
913
otp_release: 21.0
1014
- elixir: 1.7.2

lib/construct.ex

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ defmodule Construct do
3030
@type_checker_name Construct.TypeRegistry
3131
@no_default :__construct_no_default__
3232

33+
# elixir 1.9.0 do not raise deadlocks for Code.ensure_compiled/1
34+
@no_raise_on_deadlocks Version.compare(System.version(), "1.9.0") != :lt
35+
3336
@doc false
3437
defmacro __using__(opts \\ [])
3538

@@ -117,11 +120,11 @@ defmodule Construct do
117120
module = unquote(struct)
118121

119122
unless Code.ensure_compiled?(module) do
120-
raise Construct.DefinitionError, "undefined module #{module}"
123+
raise Construct.DefinitionError, "undefined module #{inspect(module)}"
121124
end
122125

123126
unless function_exported?(module, :__construct__, 1) do
124-
raise Construct.DefinitionError, "provided #{module} is not Construct module"
127+
raise Construct.DefinitionError, "provided #{inspect(module)} is not Construct module"
125128
end
126129

127130
Enum.each(module.__construct__(:types), fn({name, {type, opts}}) ->
@@ -354,13 +357,15 @@ defmodule Construct do
354357
end
355358

356359
defp check_type_complex!(module) do
360+
if @no_raise_on_deadlocks, do: Code.ensure_compiled(module)
361+
357362
unless construct_module?(module) do
358363
unless Code.ensure_compiled?(module) do
359-
raise Construct.DefinitionError, "undefined module #{module}"
364+
raise Construct.DefinitionError, "undefined module #{inspect(module)}"
360365
end
361366

362367
unless function_exported?(module, :cast, 1) do
363-
raise Construct.DefinitionError, "undefined function cast/1 for #{module}"
368+
raise Construct.DefinitionError, "undefined function cast/1 for #{inspect(module)}"
364369
end
365370
end
366371
end
@@ -407,8 +412,6 @@ defmodule Construct do
407412
end
408413

409414
defp construct_module?(module) do
410-
Code.ensure_compiled(module)
411-
412415
Agent.get(@type_checker_name, &MapSet.member?(&1, module)) ||
413416
Code.ensure_compiled?(module) && function_exported?(module, :__construct__, 1)
414417
end

test/integration/build_test.exs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,19 @@ defmodule Construct.Integration.BuildTest do
120120
end
121121

122122
test "raise when trying to use undefined module as custom type" do
123-
assert_raise(Construct.DefinitionError, ~s(undefined module Elixir.UndefinedModule), fn ->
123+
assert_raise(Construct.DefinitionError, ~s(undefined module UndefinedModule), fn ->
124124
create_construct do
125125
field :key, UndefinedModule
126126
end
127127
end)
128128

129-
assert_raise(Construct.DefinitionError, ~s(undefined module Elixir.UndefinedModule), fn ->
129+
assert_raise(Construct.DefinitionError, ~s(undefined module UndefinedModule), fn ->
130130
create_construct do
131131
field :key, {:array, UndefinedModule}
132132
end
133133
end)
134134

135-
assert_raise(Construct.DefinitionError, ~s(undefined module Elixir.UndefinedModule), fn ->
135+
assert_raise(Construct.DefinitionError, ~s(undefined module UndefinedModule), fn ->
136136
create_construct do
137137
field :key, {:map, UndefinedModule}
138138
end
@@ -144,33 +144,33 @@ defmodule Construct.Integration.BuildTest do
144144
end
145145
end)
146146

147-
assert_raise(Construct.DefinitionError, ~s(undefined module Elixir.UndefinedModule), fn ->
147+
assert_raise(Construct.DefinitionError, ~s(undefined module UndefinedModule), fn ->
148148
create_construct do
149149
field :key, [UndefinedModule]
150150
end
151151
end)
152152

153-
assert_raise(Construct.DefinitionError, ~s(undefined module Elixir.UndefinedModule), fn ->
153+
assert_raise(Construct.DefinitionError, ~s(undefined module UndefinedModule), fn ->
154154
create_construct do
155155
field :key, [CustomType, UndefinedModule]
156156
end
157157
end)
158158
end
159159

160160
test "raise when trying to use custom type that doesn't have cast/1 function" do
161-
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for Elixir.CustomTypeEmpty), fn ->
161+
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for CustomTypeEmpty), fn ->
162162
create_construct do
163163
field :key, CustomTypeEmpty
164164
end
165165
end)
166166

167-
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for Elixir.CustomTypeEmpty), fn ->
167+
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for CustomTypeEmpty), fn ->
168168
create_construct do
169169
field :key, {:array, CustomTypeEmpty}
170170
end
171171
end)
172172

173-
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for Elixir.CustomTypeEmpty), fn ->
173+
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for CustomTypeEmpty), fn ->
174174
create_construct do
175175
field :key, {:map, CustomTypeEmpty}
176176
end
@@ -182,29 +182,29 @@ defmodule Construct.Integration.BuildTest do
182182
end
183183
end)
184184

185-
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for Elixir.CustomTypeEmpty), fn ->
185+
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for CustomTypeEmpty), fn ->
186186
create_construct do
187187
field :key, [CustomTypeEmpty]
188188
end
189189
end)
190190

191-
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for Elixir.CustomTypeEmpty), fn ->
191+
assert_raise(Construct.DefinitionError, ~s(undefined function cast/1 for CustomTypeEmpty), fn ->
192192
create_construct do
193193
field :key, [CustomType, CustomTypeEmpty]
194194
end
195195
end)
196196
end
197197

198198
test "raise when trying to include undefined module" do
199-
assert_raise(Construct.DefinitionError, ~s(undefined module Elixir.UndefinedModule), fn ->
199+
assert_raise(Construct.DefinitionError, ~s(undefined module UndefinedModule), fn ->
200200
create_construct do
201201
include UndefinedModule
202202
end
203203
end)
204204
end
205205

206206
test "raise when trying to include invalid structure (some module)" do
207-
assert_raise(Construct.DefinitionError, ~s(provided Elixir.CustomTypeEmpty is not Construct module), fn ->
207+
assert_raise(Construct.DefinitionError, ~s(provided CustomTypeEmpty is not Construct module), fn ->
208208
create_construct do
209209
include CustomTypeEmpty
210210
end

0 commit comments

Comments
 (0)