#Dynamically created test functions?
1 messages · Page 1 of 1 (latest)
you wouldnt be able to use gleeunit cause thats not what its designed for, but there's nothing stopping you from making your own test runner and calling that in your test module's main function instead of gleeunit
Whats wrong with codegen?
Just an extra step to have to run rather than gleam test 🤷♂️
Ok, makes sense. But to clarify there is nothing you know of currently supporting this in gleeunit?
yeah thats not in scope for gleeunit
cool
Thank you then!
I don't have time to do that right now but would be a fun project eventually
theres also nothing special about gleeunit, just cause its added as a dependency when you make a new project doesnt mean you have to use it
gleam test isnt dependant on gleeunit in any way
but yeah i agree with hayleigh, i would use codegen for this
When would you have the code generaed?
an extra command to run before gleam test?
youd only need to run the codegen when the json changes
so not for every test
you could use gleam dev to run it
til. cool
to me this feels like it should not be necessary, i would expect it to just work when doing gleam test. or at least that is the experience i desire
its not an experience you can get
you could write a single test that loads the json and does whatever, in the assertion message include the name of the test or whatever
Yeah that is what I am currently doing
The your tests are dealing with json parsing and error handling
Why cant you write the tests in gleam?
the json is very big/would be very time consuming
and is external/im not updating it
it is a library-agnostic test suite from the spec of a protocol
e.g. "consume this and make sure your implementation passes/fails this input with this output"
This seems fine to me then
Cool
yeah it's definitely like
"not broken"
just would be cool to show them separately, but no worries
You dont need to use gleeunit as lily mentions, so you’re not constrained by the “tests must be named _test” convention.
Really youd write a gleam program to load the JSON and does assertions as you currently are just make sure the assertion messages are good
In case you didnt know already you can do `as …’ to show a specific message
assert thing(input) == expected as test_name
``` or something
That’s how the tests for my toml parser library works. It loads the tests copied from the official parser JS library and iterates over them
