Stream: beginners

Topic: expect return Task?


view this post on Zulip Johan Lindskogen (Dec 01 2023 at 11:59):

Hi friends! I am trying out roc for Advent of Code. When I tried defining an expect test for my input I ran into this issue:

── TYPE MISMATCH ────────────────────────────────────────────── day01/main.roc ─

This `expect` condition needs to be a Bool:

75│>      input <- File.readUtf8 (Path.fromStr "input") |> Task.await
76│>
77│>      part1 input == 232323

This `Task.await` call produces:

    InternalTask.Task c [
        FileReadErr Path.Path InternalFile.ReadErr,
        FileReadUtf8Err Path.Path [BadUtf8 Utf8ByteProblem Nat],
    ]>

I understand that the return value is wrong since I return a Task. Just wanted to confirm that expect is not made to handle effects, or is there a mistake in the code?

expect
    input <- File.readUtf8 (Path.fromStr "input") |> Task.await

    part1 input == 232323

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 12:03):

It might be easier to include the text file at compile-time, in your imports like so:

imports [ "input" as input : Str ]

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 12:03):

Unless your goal is specifically to play with the runtime effect system, or if you're looking to implement a specific API

view this post on Zulip Johan Lindskogen (Dec 01 2023 at 12:07):

You are absolutely right, I will change the tests. The reason I wasn't using it at first is because I wanted the binary to be able to handle different inputs. Not sure I can make the same case for a test.

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 15:23):

Just for more context. Long term, we plan to add expect-fx that would enable something like this where you would mock out the results of a task.

Otherwise, expect is just for pure functions and code. So you would need to add any sort of input to the file. Think of expect as really just for unit tests.


Last updated: Jul 06 2025 at 12:14 UTC