Skip to content

testable for seq and contramap (for testable)#412

Merged
MisterDA merged 5 commits intomirage:mainfrom
xvw:contramap-for-testable
Sep 23, 2024
Merged

testable for seq and contramap (for testable)#412
MisterDA merged 5 commits intomirage:mainfrom
xvw:contramap-for-testable

Conversation

@xvw
Copy link
Copy Markdown
Contributor

@xvw xvw commented Sep 5, 2024

This PR adds:

  • seq (to produces 'a Seq.t testable) Because the Seq.t type has become very common in the standard library
  • contramap which allows you to go from an 'a testable to a 'b testable giving a function from b -> 'a (because a testable is a contravariant functor). I have often found the function useful for implementing testables quickly when there is a trivial transformation.

Comment thread src/alcotest-engine/test.mli Outdated
(** [neg t] is [t]'s negation: it is [true] when [t] is [false] and it is
[false] when [t] is [true]. *)

val contramap : ('b -> 'a) -> 'a testable -> 'b testable
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.

Do you mind naming this map -- even if it doesn't follow the theory, that's what more users would expect :p

Copy link
Copy Markdown
Contributor Author

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 keeping the Fmt convention by calling it using? (Because I find that calling it map makes reading its signature ... complicated).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, btw you are right, map works well, fixed on 415abb4

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.

using could work too - no strong opinion between map and using

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I go for map :)

@samoht
Copy link
Copy Markdown
Member

samoht commented Sep 23, 2024

Thanks that looks like a great addition!

LGTM apart questions on names (the most difficult questions, as usual)

Copy link
Copy Markdown
Collaborator

@MisterDA MisterDA left a comment

Choose a reason for hiding this comment

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

Seq.uncons was introduced in OCaml 4.14. We may want to keep supporting OCaml 4.08 for a while still.

Comment thread src/alcotest-engine/test.ml
@MisterDA MisterDA merged commit 8d30762 into mirage:main Sep 23, 2024
@xvw xvw deleted the contramap-for-testable branch September 23, 2024 15:55
samoht added a commit to samoht/opam-repository that referenced this pull request Mar 13, 2025
CHANGES:

- Add `seq`, a testable for `Seq.t` and `contramap` (mirage/alcotest#412 @xvw)
- Expose the `V1.Skip` exception (mirage/alcotest#415, mirage/alcotest#416, @Khady)
- BREAKING FIX: `match_raises` now expects the user-defined function to return
  true for expected exceptions. Previously false was interpreted as an
  expected exception. (mirage/alcotest#418, mirage/alcotest#419, @psafont)
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