tutorial: writing CUE tests #4
Labels
content idea
Idea for a new piece of content
tutorial
For content that in the "tutorial" diataxis quadrant
Milestone
From Slack: https://cuelang.slack.com/archives/CLT3ULF6C/p1694277761735349
Original thread
Jan von Loewenstein [4 days ago](https://cuelang.slack.com/archives/CLT3ULF6C/p1694277761735349) Has anyone already discovered how to best write unit tests cue expressions?Tony Worm
4 days ago
testscript is the most common method for testing CUE afaik
https://github.com/rogpeppe/go-internal/tree/master/cmd/testscript
Tony Worm
4 days ago
you can test just about anything with it actually, it's pretty sweet
Tony Worm
4 days ago
Here's a bunch from the CUE source
https://github.com/cue-lang/cue/tree/master/cmd/cue/cmd/testdata/script
Jan von Loewenstein
4 days ago
Thanks, will give it a try for my current experiments.
myitcv
3 days ago
See also cue-lang/cue#209
#209
cue test
supportOriginally opened by @rudolph9 in cuelang/cue#209
Cuelang has reserved *_test.cue similar to golang but does not yet have support for actually running tests.
Unless there is a good reason to follow a different path it seems reasonable to model cuelang testing after golang testing
Ideally we would "eat our own dog food" for testing and not create new builtin function but rather express the logic of the test using cuelang.
An example of a testing package is https://github.com/ipcf/t.
myitcv
3 days ago
It's also worth pointing out that you can test simply by writing CUE itself. Either (for example) to assert that "production" values are as expected, or as separate values.
myitcv
3 days ago
We'll be writing up a couple of examples for https://alpha.cuelang.org/
Jan von Loewenstein
3 days ago
The "write tests in CUE" was what I initially had in mind when asking. But it seems right to follow whatever approach has established usage in the community atm
myitcv
3 days ago
Both would be "right" to my mind. In many ways, testscript is just a "runner" for a test of cmd/cue calls
Jan von Loewenstein
3 days ago
What I meant was the vast amount of precedent using testscript, including the notion of running a test and having them pass or fail.
Jan von Loewenstein
3 days ago
For pure cue based tests I would assume that at least now nothing like that exists
Tony Worm
3 days ago
What are you testing exactly?
The CUE evaluator does a lot of solving and validating already,
Jan von Loewenstein
3 days ago
I'll want to test that the user input via values leads to the expected results
Tony Worm
3 days ago
that's a great use-case for testscript, there are things like "functions" that might be easier (or look like more traditional tests) to write tests for in native CUE. I'm curious what people are thinking for that syntax
myitcv
2 days ago
This is also possible in pure CUE
myitcv
2 days ago
https://tip.cuelang.org/play/?id=zzrdUyEYU0e#cue@export@cue
myitcv
2 days ago
cc
@Jonathan Matthews
Jan von Loewenstein
2 days ago
I like the @if(test) a lot
OP asks for guidance about "how to best write unit tests [for] cue expressions".
Testscript is mentioned, as is the
... conditional file-level inclusion syntax.
The text was updated successfully, but these errors were encountered: