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

Improve documentation on test case filtering and flush error formatter on exit #133

Merged
merged 5 commits into from
May 21, 2018

Conversation

edwintorok
Copy link
Contributor

Filtering testcases was scarcely documented (had to read the source code to find out the expected format): add an example to the README, and make --help more explicit that up to 2 arguments can be used for filtering (the name of the test, and the test case index).

Also fix a bug with error messages getting lost on exit: OCaml doesn't flush Format.stderr on exit, just Format.stdout, so we have to flush it ourselves.

The improved output compared to the old one looks like this:

--- old
+++ new
@@ -1,15 +1,19 @@
 + ./simple test test_set invalidnumber
+simple: TESTCASE argument: invalid value `invalidnumber', expected an integer
+Usage: simple test [OPTION]... [NAME] [TESTCASE]
+Try `simple test --help' or `simple --help' for more information.
 Testing My first test.
 + echo '$?=' 1
 $?= 1

 + ./simple test nonexistent_name
+Invalid request (no tests to run, filter skipped everything)!
 Testing My first test.
 + echo '$?=' 1
 $?= 1

 + ./simple test test_set 1 trailingarguments
-simple: internal error, uncaught exception:
-        Failure("filter_test")
-
+simple: too many arguments, don't know what to do with `trailingarguments'
+Usage: simple test [OPTION]... [NAME] [TESTCASE]
+Try `simple test --help' or `simple --help' for more information.
 Testing My first test.
 + echo '$?=' 1
 $?= 1

No doubt the documentation could be improved further, this is just a start.

OCaml's standard library only flushed the stdout formatter:
https://github.com/ocaml/ocaml/blob/4.06.1/stdlib/format.ml#L1371

This meant that the 'Invalid request!' error message was never shown
when an invalid filter was used.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
If a filter removes everything and we are left with no tests to run
then an "Invalid request!" error was shown.
Point out that the problem is with the filter.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Use Cmdliner for converting int to string, and validating the number of
arguments.
Previously just a Failure message was shown with no clear indication to
what is wrong, now more details are shown:

```diff
--- old
+++ new
@@ -1,15 +1,19 @@
 + ./simple test test_set invalidnumber
+simple: TESTCASE argument: invalid value `invalidnumber', expected an integer
+Usage: simple test [OPTION]... [NAME] [TESTCASE]
+Try `simple test --help' or `simple --help' for more information.
 Testing My first test.
 + echo '$?=' 1
 $?= 1

 + ./simple test nonexistent_name
+Invalid request (no tests to run, filter skipped everything)!
 Testing My first test.
 + echo '$?=' 1
 $?= 1

 + ./simple test test_set 1 trailingarguments
-simple: internal error, uncaught exception:
-        Failure("filter_test")
-
+simple: too many arguments, don't know what to do with `trailingarguments'
+Usage: simple test [OPTION]... [NAME] [TESTCASE]
+Try `simple test --help' or `simple --help' for more information.
 Testing My first test.
 + echo '$?=' 1
 $?= 1
```

This does not change the semantics of what CLI arguments are accepted,
just the help text and error reporting.
From the usage example it is clear now that only 2 filters can be used.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Copy link

@gaborigloi gaborigloi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@samoht
Copy link
Member

samoht commented May 21, 2018

Thanks!

@samoht samoht merged commit cb93251 into mirage:master May 21, 2018
samoht added a commit to samoht/opam-repository that referenced this pull request Oct 17, 2018
CHANGES:

- Improve documentation for speed and tests (mirage/alcotest#129, @raphael-proust)
- Improve documentation on test case filtering and flush error formatter on exit
  (mirage/alcotest#133, @edwintorok)
- Create a fresh log sub-dir for every run (mirage/alcotest#125, @M-Harrison)
- Fix wrong location hint for test files when using dune (mirage/alcotest#135, @M-Harrison)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants