Testing Spark Validator compilation warnings

I maintain some Ash Extensions that use Spark, and now have some ExUnit regression tests which used to assert_raise fine but now after upgrading ash deps for recent CVE spark also updated (2.2.68 to 2.3.5) and the Spark.Error.DslError's are no longer raised rather they are compile time warnings. I'd still like to test my Validators though, and there is no ExUnit.assert_warning. Likely that this has been encountered/solved some where in Ash already, what is the way forward here?
Solution:
Yep, we were forced to make that change
Jump to solution
3 Replies
Solution
ZachDaniel
ZachDaniel2mo ago
Yep, we were forced to make that change
ZachDaniel
ZachDaniel2mo ago
The way we test that is by using ExUnit's capture_io functionality
Matt Beanland
Matt BeanlandOP2mo ago
Thanks Zach. For others what I did was added a Test.Util function
def assert_compile_time_warning(module, message, fun) do
output = capture_io(:stderr, fun)
assert output =~ String.trim_leading("#{module}", "Elixir.")
assert output =~ message
end
def assert_compile_time_warning(module, message, fun) do
output = capture_io(:stderr, fun)
assert output =~ String.trim_leading("#{module}", "Elixir.")
assert output =~ message
end
and used it like
test "label: invalid label warns DslError on compilation" do
fun = fn ->
defmodule InvalidLabel do
use Ash.Resource,
domain: AshNeo4j.Test.Domain,
data_layer: AshNeo4j.DataLayer

neo4j do
label :comment
translate id: :uuid
end

attributes do
uuid_primary_key :id
attribute :title, :string, public?: true
end
end
end
Util.assert_compile_time_warning(Spark.Error.DslError, "label: neo4j label must be PascalCase", fun)
end
test "label: invalid label warns DslError on compilation" do
fun = fn ->
defmodule InvalidLabel do
use Ash.Resource,
domain: AshNeo4j.Test.Domain,
data_layer: AshNeo4j.DataLayer

neo4j do
label :comment
translate id: :uuid
end

attributes do
uuid_primary_key :id
attribute :title, :string, public?: true
end
end
end
Util.assert_compile_time_warning(Spark.Error.DslError, "label: neo4j label must be PascalCase", fun)
end

Did you find this page helpful?