Skip to content

Make alcotest usable on Mirage - #238

Merged
craigfe merged 32 commits into
mirage:masterfrom
robur-coop:mirage
May 19, 2020
Merged

craigfe merged 32 commits into
mirage:masterfrom
robur-coop:mirage

Conversation

@linse

@linse linse commented Apr 17, 2020

Copy link
Copy Markdown
Contributor

With this PR, we make alcotest usable in a MirageOS unikernel.
We moved the unix-specific code into the alcotest.unix sublibrary and defined the module signature Platform for code that depends on the platform. In there, we do

  • directory creation
  • redirect stdout / sderr to files
  • set the style renderer.

We implemented the opam package alcotest-mirage for MirageOS unikernel testing. An example is in test/e2e/alcotest-mirage.

We would love your input on

  • the semantics of Alcotest.run: no longer redirects output to files, independent of Unix - is that change a problem?
  • Alcotest_unix.run behaves like Alcotest.run => should Alcotest.run be removed (API change)?
  • other approaches, such as deprecation warning on use of Alcotest.run?

@craigfe

craigfe commented Apr 17, 2020

Copy link
Copy Markdown
Member

Thanks for the contribution! Mirage support is very fitting (and overdue).

The implementation looks good overall (though I have some quibbles such as a general lack of documentation for the new module types).


I'm less keen about the naming of the package split (alcotest, alcotest.lwt & alcotest-mirage), for two reasons:

  • I think Dune dependencies and Opam packages should be kept in 1:1 correspondence unless strictly necessary, as I think the alternative is confusing for new users.
  • I suspect the change of semantics to Alcotest.run will be problematic for most users – personally I find the file redirection feature really important for any non-trivial codebase – and so I imagine the switch to Alcotest_unix.run generating a lot of downstream churn.

My counter-proposal is to split as follows:

  • alcotest-kernel (?): contains the platform-agnostic test runner (i.e. what alcotest is currently in this PR);
  • alcotest-mirage: instantiates the runner with Mirage + Lwt logic;
  • alcotest: instantiates the runner with Unix + Identity, providing exactly the same API / semantics as it currently does.

If I understand correctly, this split has the benefit of being invisible to all current users of Alcotest. It also avoids the question of what to do about the CLI params that don't make sense without file redirection (--tail-errors, --show-errors, --verbose and to some extent --compact).

@samoht

samoht commented Apr 17, 2020

Copy link
Copy Markdown
Member

Thanks for your patch!

A very quick review: I like the approach of the patch (abstracting away the platform specific bits). However I am not fond of changing UX regarding Alcotest.run that 99% of our users will be using. Ideally, this function should not change (and be an alias for Alcotest_unix.run) without brining unix dependencies to alcotest-mirage. Maybe this could be done by re-arranging the modules a bit?

@Lupus

Lupus commented Apr 17, 2020

Copy link
Copy Markdown

Dune virtual libraries might be a good fit to solve this problem. In this case Alcotest.run would remain and maintain existing behavior, unix could be listed as default implementation, which is also backwards-compatible, yet other implementations can be plugged in to support mirage, js, other platforms.

@hannesm

hannesm commented Apr 23, 2020

Copy link
Copy Markdown
Member

Hi,

we improved this PR as you requested. Now, there is a alcotest-core opam package which does not depend on Unix. The alcotest API is unmodified (apart from the functors which are only exported via alcotest-core).

The AppVeyor error is unrelated (curl is missing on cygwin); the OCaml-CI error in 4.06.0 is an OCaml outputting change (which is different in newer OCaml versions -- Alcotest_core.Core vs Alcotest_core__Core) - we're not sure how to fix this.

We hope this version works for you and can be merged. If not, ping us.

@craigfe craigfe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Regarding the Alcotest_core__Core vs Alcotest_core.Core discrepancy, we can special case this as a regex in the output sanitizer. We're already handling similar platform-dependent output re. test duration, UUIDs, and build output paths.

Some thoughts:

Comment thread dune-project Resolved
Comment thread dune-project Resolved
Comment thread src/alcotest-core/platform.mli Resolved
Comment thread src/alcotest/alcotest.mli Resolved
Comment thread src/alcotest/alcotest.mli Resolved
@samoht

samoht commented Apr 25, 2020 •

Copy link
Copy Markdown
Member

Thanks for your changes. I'll review this more carefully next week, but I don't think that adding a new opam package (alcotest-core) is needed here.

linse and others added 21 commits May 4, 2020 13:32
Adapt tests to use Alcotest_unix.run

Co-Authored-By: linse <[email protected]>
The new alcotest-core package is independent of unix

The alcotest API is mostly unmodified

Co-Authored-By: linse <[email protected]>
@hannesm

hannesm commented May 7, 2020 •

Copy link
Copy Markdown
Member

CI passes, we needed to include Sys.getcwd into platform. Would be great to get this reviewed and merged @craigfe @samoht .

@samoht

samoht commented May 8, 2020

Copy link
Copy Markdown
Member

LGTM

@craigfe you mentioned this could break for projects using (implicit_transitive_deps false). Do you have an example in mind?

@craigfe

craigfe commented May 11, 2020

Copy link
Copy Markdown
Member

@craigfe you mentioned this could break for projects using (implicit_transitive_deps false). Do you have an example in mind?

@samoht: for instance, the type of test filters is no longer observable without explicitly including alcotest.core in the libraries stanza:

ᐅ dune exec test/test.exe
File "test/test.ml", line 269, characters 36-48:
269 |     Alcotest_lwt.run ~filter:(None, IntSet.empty) "test" [
                                          ^^^^^^^^^^^^
Error: This expression has type IntSet.t
       but an expression was expected of type
         Alcotest_core__.Core.IntSet.t option

On closer inspection, this may be the only such case (in which case it's hardly an issue).

The greater breakage is probably that the Alcotest.Cli and Alcotest.Core modules no longer exist: this is a breaking change for OCurrent (albeit only because it was working around a bug that has now been fixed).

@hannesm

hannesm commented May 11, 2020

Copy link
Copy Markdown
Member

The greater breakage is probably that the Alcotest.Cli and Alcotest.Core modules no longer exist: this is a breaking change for OCurrent (albeit only because it was working around a bug that has now been fixed).

I'm not a fan of re-exporting modules, that's why they no longer exist - if you re-export them and then use the functors with the wrong paths, this leads to compilation errors. I also think of them as internal modules, and unlikely being used outside of alcotest.

alcotest.core vs alcotest-core

I don't mind either.

@craigfe

craigfe commented May 18, 2020

Copy link
Copy Markdown
Member

I'm not a fan of re-exporting modules, that's why they no longer exist - if you re-export them and then use the functors with the wrong paths, this leads to compilation errors. I also think of them as internal modules, and unlikely being used outside of alcotest.

I don't think it's a case of re-exporting modules so much as pre-applying them with the Unix platform. I wouldn't suggest providing those helpers if it weren't a matter of backwards compatibility with the functors that were there before. Perhaps @samoht has some thoughts on this.


I've PRed into this one with some proposed changes (see https://github.com/roburio/alcotest/pull/1). Copying the PR description from there:

  • rename alcotest.core to alcotest.engine to avoid any confusion with JS packages (I think this is a better descriptor anyway);

  • cleanup the Mirage Platform functor to be slightly less brittle (avoid reference to Pp.run_result), and use this to hide some internal modules inside a Private wrapper;

  • provide test runner functors with Unix pre-applied (this keeps some degree of backwards compatibility);

  • add a CHANGES entry.

In my opinion, with those changes the PR can be merged. Don't let that block further discussion if you disagree with my proposals.

@Lupus Lupus mentioned this pull request May 18, 2020
Assorted cleanup to the proposed alcotest-mirage package
@craigfe

craigfe commented May 19, 2020 •

Copy link
Copy Markdown
Member

Will merge as #244 when the CI passes there (can't push to this branch). It contains a test fix that I forgot to include in my branched PR.

edit: or @hannesm will beat me to it 😁

@hannesm

hannesm commented May 19, 2020

Copy link
Copy Markdown
Member

@craigfe thanks for your PR, we merged it. This is good to be merged now.

@craigfe

craigfe commented May 19, 2020

Copy link
Copy Markdown
Member

Thanks for the contribution 😊

@craigfe
craigfe merged commit e013f8c into mirage:master May 19, 2020
craigfe added a commit to craigfe/opam-repository that referenced this pull request Jul 13, 2020
…age (1.2.0)

CHANGES:

- Add an `alcotest-mirage` package, allowing the construction of MirageOS
  unikernels that run Alcotest test suites. (mirage/alcotest#238, @hannesm @linse)

- Add `Alcotest.check'`, a variant of `Alcotest.check` with labeled arguments.
  (mirage/alcotest#239, @hartmut27)

- Add a testable for the `bytes` type. (mirage/alcotest#253, @mefyl)

- Many assorted improvements to Alcotest output formatting. (mirage/alcotest#246, @craigfe)

- Default to `--color=always` when running inside Dune (mirage/alcotest#242, @craigfe). The
  value can be overridden by setting the `ALCOTEST_COLOR` variable in a `dune`
  file, for example:

```dune
(env
 (_
  (env-vars
   (ALCOTEST_COLOR auto))))
```

- Support all UTF-8 characters in test names and suite names, by normalising
  them for file-system interactions. (mirage/alcotest#249, @gs0510; mirage/alcotest#246, @craigfe)

- Fix various crashes when using non-filesystem-safe characters in test suite
  names (these break Alcotest when attempting to generate a corresponding log
  file). (mirage/alcotest#241, @mefyl; mirage/alcotest#246 @craigfe)
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.

5 participants