-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add DSL for compilation failing tests #15
Comments
I've done something similar within Spectator itself to test syntax. I can see how this would be useful in other scenarios. https://gitlab.com/arctic-fox/spectator/-/blob/specs/spec/runtime_example_spec.cr Maybe a new type of matcher that compiles crystal code? Perhaps something like: let(:code) { "puts \"some crystal code here\"" }
let(:malformed_code) { "this won't work" }
specify { expect(code).to compile }
specify { expect(code).to_not compile.with_error(/syntax/) } |
Nice matcher! Wouldn't be easier to have a way to specify a file instead of a string? Because it's simpler to write clean code in a file instead of a string, and most of the time it seems the code to compile would have many lines. edit: I mean an easier way instead of having to do a |
The code could be cleaned up with some multi-line strings and macros. Something like: let(:code) do
<<-EOS
puts "do something"
EOS
end macro source_code(name, &block)
let({{name.id}}) do
{{block.body.stringify}}
end
end
source_code(:sample) do
puts "another example"
end The matcher could also accept a let(:code_file) { File.new("foo.cr") }
specify { expect(code_file).to compile } or even a utility: macro expect_file(file)
expect(File.new({{file}})).to compile
end
specify { expect_file("foo.cr").to compile } Templates and string substitution can be done with the first approach, but for passing a file, something like ECR could be used. |
All your examples are really interesting. I didn't think about defining a macro to handle the source code in place and having the syntax highlighting at the same time., this is nice. But maybe the simpler (to implement, and for the user) would be to just have an |
When developing my Origin shard (https://github.com/pyrsmk/origin), I needed to test that the compilation is failing properly when using the shard wrongly. This is especially useful when coding a macro.
Here's what I came with in a helper:
Here, we're defining a
wire/wrong_typing.cr
with a wrong implementation of the macro. We can then test it in an example:What are your thoughts?
The text was updated successfully, but these errors were encountered: