-
Notifications
You must be signed in to change notification settings - Fork 412
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
Test Stanza Proposal #822
Test Stanza Proposal #822
Conversation
The idea seems fine to me. I suggest to add a field |
@diml that would be really nice. Would this work for a |
I suppose for |
@diml Another problem to solve for type expected_output =
| Output of string
| Correction of stirng A value without a constructor can be interpreted with |
What would the two constructors correspond to in the |
The first one would correspond to the |
|
Thinking about this again, we could enable the diffing automatically if the there is a file |
Jérémie Dimino <notifications@github.com> writes:
`diif?` is for command that optionally produce a corrected file. In this case it would always exist, since we would create it by capturing the output of the command.
Yeah, so I think that expected_outputs will not support such commands.
I'd expect that we'd support both styles of expect tests in the tests
stanaza.
|
Jérémie Dimino <notifications@github.com> writes:
Thinking about this again, we could enable the diffing automatically if the there is a file `<name>.expected` in the source tree. It's probably how it will always be called.
That sounds like a good idea. It will also solve the problem of ordering
the arguments in the diff action. I always forget if the expected file
comes first or second.
I'm still wondering if we should make this opt in by adding an
(expect_tests) option to enable this.
|
I don't think it's necessary. Adding a file named |
Will this auto discovery work when we have a rule producing |
No it wouldn't. However, a .expected file that is not committed in the repository kinds of defeat the purpose of expectation testing. |
Jérémie Dimino <notifications@github.com> writes:
No it wouldn't. However, a .expected file that is not committed in the
repository kinds of defeat the purpose of expectation testing.
I'm still a little uneasy about doing file IO during parsing like this.
But will give this a try.
|
Note that for this case we would just consult the |
@diml should we make use of the parsing context to pass this File_tree parameter btw? Or should we just pass the parameter manually. |
Why do we need it during parsing? Shouldn't we check the file tree while setting up the rules for the Test stanza? |
Jérémie Dimino <notifications@github.com> writes:
Why do we need it during parsing? Shouldn't we check the file tree
while setting up the rules for the Test stanza?
The way the tests stanza currently works is that there's really nothing
but a parsing stage. The tests stazna is simply immediately converted to
an alias and an exe stanzas.
I suppose I could just delay some of this process until gen_rules and
then I will have access to the file tree that I need.
|
okay @diml I've changed the approach to something that is more gen_rules heavy and also prototyped the expectation tests detection. That bit still needs some tests, but you can already review the general approach. |
The code works but unfortunately the restriction on aliases not having targets is biting me here. I'll change the code to generate a separate rule. Why did we have that restriction again? @emillon btw, have a look at this PR as well. |
One thing that's slightly wonky is that @diml do you have a suggestion on how to address this? AFAIK, this doesn't actually cause any harm apart from having the .output files generated invisible as mld or ml sources. Which wouldn't really make sense anyway. |
About the feature itself, I think it's useful to add a short syntax for this, since it's a common use case. The plural version A singular version |
src/jbuild.ml
Outdated
let t = | ||
record | ||
(Buildable.t >>= fun buildable -> | ||
field_oslu "link_flags" >>= fun link_flags -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be the best place to start a discussion about code style, but I don't think that aligning these (>>=)
is a good idea. It will either require some maintenance effort every time we modify anything in that block, or become unaligned. This is not worth the minor readability benefit IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I just try to follow whatever existing style is in place. Here I've failed because it is indeed troublesome without some sort of automation.
@@ -0,0 +1,2 @@ | |||
(tests | |||
(names bar foo)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about using the "expect" and "regular" names for these two tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So have 2 fields? E.g.
(tests
(regular foo bar)
(expect baz blue))
Yeah, I definitely like this proposal. Though I would switch regular to something like run
. I think @diml has a preference for auto discovery here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I meant using a-regular-test
and an-expect-test
instead of foo
and bar
.
As for autodiscovery vs constructor, I think that the idea of this proposal is to have a very light syntax to define test executables, so I lean slightly towards auto discovery here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. I renamed all the tests. Okay, auto discovery it is.
Sure I'll add this. |
Okay, I added a singular form. Honestly, I think that these singular forms don't have benefits to justify their existence but for symmetry I guess we should allow them. |
I've added documentation for this stanza now. I think it's a pretty simple addition and hence can make it to 1.0 |
doc/dune-files.rst
Outdated
expect test. That is, the test will be executed and its output will be compared | ||
to ``expect_test.expected``. | ||
|
||
The optional fields that are supported a subset of alias and executables fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a word missing in this sentence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed.
The stanza is used to define executables that are tests all at once. Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
and also support expectation tests Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Use test names that reflect what is being tested Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Problem
Creating tests in dune requires quite a bit of extra boilerplate. To define n tests, one needs at least
executables
stanzas and nalias
stanzas. For example, here's a snippet from ocaml-re that shows how this boilerplate can get out hand:Proposal
Add a
tests
stanza that will allow us to define executables and attach appropriateruntest
aliases to run them. A test suite composed of multiple executables would look like:The
tests
stanza would support fields common toalias
andexecutables
that make sense for tests. This would exclude fields likepublic_names
for example. This would also allow us to add test specific abilities down the road. One such example would be an(expected_output <filename>)
field that could make it easy to write expect tests.