Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tutorial: writing CUE tests #4

Open
myitcv opened this issue Oct 11, 2023 · 0 comments
Open

tutorial: writing CUE tests #4

myitcv opened this issue Oct 11, 2023 · 0 comments
Labels
content idea Idea for a new piece of content tutorial For content that in the "tutorial" diataxis quadrant
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented Oct 11, 2023

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 support
Originally 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

  • we did something similar with the Terraform+CUE experiment

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

@if(test)
package p

x: some.tests

... conditional file-level inclusion syntax.

@myitcv myitcv added tutorial For content that in the "tutorial" diataxis quadrant content idea Idea for a new piece of content labels Oct 11, 2023
@jpluscplusm jpluscplusm added this to the priority milestone Dec 18, 2023
@jpluscplusm jpluscplusm self-assigned this Dec 20, 2023
@jpluscplusm jpluscplusm removed their assignment Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content idea Idea for a new piece of content tutorial For content that in the "tutorial" diataxis quadrant
Projects
Status: Backlog
Development

No branches or pull requests

2 participants