Stream: beginners

Topic: Expect keyword


view this post on Zulip Martin Stewart (Jul 19 2022 at 20:35):

Is there documentation on how expect works? As I understand it, it's a keyword you write within a function that tests a condition when that function is executed? If yes, can I write unit tests with it by adding top level functions that only contain expect?

view this post on Zulip Folkert de Vries (Jul 19 2022 at 20:38):

you can write top-level expects

view this post on Zulip Qqwy / Marten (Sep 16 2023 at 19:15):

Hi all! I have a question about using expect to create a basic test suite for a Roc library.
Essentially: Is there a way to import modules/functions _only_ for use inside expect?

view this post on Zulip Qqwy / Marten (Sep 16 2023 at 19:20):

In this case I'm extracting the Base64 example from the main Roc repo, and I want to write a bunch of tests to make sure it works well.
These mostly have the form of

But my problem is that I don't always want to depend on the Decode module in the Encode module and vice-versa. (Which is not even possible because of cyclic dependencies), but only for the expects.

view this post on Zulip Qqwy / Marten (Sep 16 2023 at 19:21):

How to approach this? Move the expects to a third module that is not exposed from the library called MyLib.Test maybe?

view this post on Zulip Brian Carroll (Sep 16 2023 at 19:25):

Yeah I think I'd make test module in this situation

view this post on Zulip Qqwy / Marten (Sep 16 2023 at 19:26):

How do you set up the test module as part of a package? I tried changing

package "Base64"
    exposes [
        Base64,
        Base64.Encode,
        Base64.Decode,
    ]
    packages {}

to

package "Base64"
    exposes [
        Base64,
        Base64.Encode,
        Base64.Decode,
    ]
  imports [
    Test
  ]
    packages {}

But that does not compile.

view this post on Zulip Qqwy / Marten (Sep 16 2023 at 19:26):

Moving it to Base64.Test and creating a Base64.roc module which contains only

interface Base64
    exposes []
    imports [Base64.Test]

does sort of work (the expectation is found), but gives an unused module warning

view this post on Zulip Richard Feldman (Sep 16 2023 at 19:58):

interesting! I think we should have a nicer solution for this (which will require some design work) but in the meantime a workaround is to have Base64.Test expose something useless (like Tests := []) and then have Base64 do something like _tests : Base64.Test.Tests - I'm on my phone, but I think that should address the unused warning


Last updated: Jul 06 2025 at 12:14 UTC