Hi again
, I have a question, when I move my module and macro inside a test, it does not work, I think inside test it takes a time to compile and the functions are called faster than the macro
for example:
test "nested macro field" do
defmodule TestNestedStruct do
use GuardedStruct
guardedstruct do
field(:title, String.t())
field(:subject, String.t())
sub_field(:oop, String.t(), enforce: true) do
field(:title, String.t())
field(:fam, String.t())
sub_field(:soos, String.t(), enforce: true) do
field(:fam, String.t())
end
end
field(:site, String.t())
end
end
IO.inspect(TestNestedStruct.__struct__())
IO.inspect(TestNestedStruct.Oop.__struct__())
IO.inspect(TestNestedStruct.Oop.__info__(:functions))
IO.inspect(TestNestedStruct.Oop.Soos.__struct__())
IO.inspect(TestNestedStruct.Oop.Soos.__info__(:functions))
IO.inspect(TestNestedStruct.keys())
assert %TestNestedStruct.Oop{
fam: nil,
title: nil
} = TestNestedStruct.Oop.__struct__()
end
The error:
error: MishkaDeveloperToolsTest.GuardedStructTest.TestNestedStruct.Oop.__struct__/0 is undefined, cannot expand struct MishkaDeveloperToolsTest.GuardedStructTest.TestNestedStruct.Oop. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code
test/guarded_struct_test.exs:542: MishkaDeveloperToolsTest.GuardedStructTest."test nested macro field"/1
But if I move the module out of test macro, it works like:
defmodule TestNestedStruct do
use GuardedStruct
guardedstruct do
field(:title, String.t())
field(:subject, String.t())
sub_field(:oop, String.t(), enforce: true) do
field(:title, String.t())
field(:fam, String.t())
sub_field(:soos, String.t(), enforce: true) do
field(:fam, String.t())
end
end
field(:site, String.t())
end
end
test "nested macro field" do
IO.inspect(TestNestedStruct.__struct__())
IO.inspect(TestNestedStruct.Oop.__struct__())
IO.inspect(TestNestedStruct.Oop.__info__(:functions))
IO.inspect(TestNestedStruct.Oop.Soos.__struct__())
IO.inspect(TestNestedStruct.Oop.Soos.__info__(:functions))
IO.inspect(TestNestedStruct.keys())
assert %TestNestedStruct.Oop{
fam: nil,
title: nil
} = TestNestedStruct.Oop.__struct__()
end
If i put the output of __struct__
inside a variable, it print the output but it shows me this warning
....warning: MishkaDeveloperToolsTest.GuardedStructTest.TestNestedStruct.Oop.__struct__/0 is undefined (module MishkaDeveloperToolsTest.GuardedStructTest.TestNestedStruct.Oop is not available or is yet to be defined)
test/guarded_struct_test.exs:541: MishkaDeveloperToolsTest.GuardedStructTest."test nested macro field"/1