Stream: beginners

Topic: "expect" feature


view this post on Zulip Ghislain (Nov 09 2022 at 11:43):

Hi,
I would like to know the current expectations I can have with expect, or if I'm using it in a wrong way. My current observations are:

  1. It doesn't work inside functions
  2. It works outside functions but prints a different message if the variable is declared inside or outside of the expect scope.
    Screenshot-2022-11-09-at-12.40.12.png

view this post on Zulip Folkert de Vries (Nov 09 2022 at 11:49):

it should work inside functions too when you use roc dev file.roc with a recent build of the compiler

view this post on Zulip Folkert de Vries (Nov 09 2022 at 11:50):

assuming the expect is reached from main

view this post on Zulip Anton (Nov 09 2022 at 11:55):

I just uploaded the latest nightlies (except for macos x86_64) so those should be good

view this post on Zulip Ghislain (Nov 09 2022 at 12:03):

I built today from the source, to be sure I tested with your nightlies @Anton but I get the same output

view this post on Zulip Folkert de Vries (Nov 09 2022 at 12:07):

well yeah so regarding what is shown: your observations are roughly correct. We look at what values are captured by the expect. other top-level values are constants, so they are not considered to be captured. So maybe we should tweak that slightly

view this post on Zulip Folkert de Vries (Nov 09 2022 at 12:10):

inline expects do work right? This is with latest main

main =
    expect 1 == 2
    "Roc <3 Zig!\n"

gives

> cargo run -- dev examples/platform-switching/rocLovesZig.roc
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
     Running `target/debug/roc dev examples/platform-switching/rocLovesZig.roc`
๐Ÿ”จ Rebuilding platform...
Roc <3 Zig!
runtime: 0.057ms
โ”€โ”€ EXPECT FAILED โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ examples/platform-switching/rocLovesZig.roc โ”€

This expectation failed:

7โ”‚      expect 1 == 2
               ^^^^^^โŽ

view this post on Zulip Ghislain (Nov 09 2022 at 12:16):

Ok, there is something weird on my Mac, I did exactly the same and I don't get the EXPECT FAILED:

$ cat examples/platform-switching/rocLovesZig.roc
app "rocLovesZig"
    packages { pf: "zig-platform/main.roc" }
    imports []
    provides [main] to pf

main =
    expect 1 == 2
    "Roc <3 Zig!\n"
$ cargo run -- dev examples/platform-switching/rocLovesZig.roc
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/roc dev examples/platform-switching/rocLovesZig.roc`
๐Ÿ”จ Rebuilding platform...
Roc <3 Zig!
runtime: 0.075ms
$

view this post on Zulip Folkert de Vries (Nov 09 2022 at 12:31):

interesting! we'll have to debug that then. On linux it does work, so there must be some subtle difference again that makes it fail on mac

view this post on Zulip Folkert de Vries (Nov 09 2022 at 12:32):

@Ayaz Hafiz it did work on mac at some point right?

view this post on Zulip Folkert de Vries (Nov 09 2022 at 12:33):

maybe it's a good idea to strace (does that work on mac?) the process to see what syscalls actually happen

view this post on Zulip Ayaz Hafiz (Nov 09 2022 at 13:54):

fwiw I never got inline expects to work on the M1 I use

view this post on Zulip Ayaz Hafiz (Nov 09 2022 at 13:55):

I see no execution at all as of e589dc88a3dfc2d5bc14aac1c7d319d716bece0a

app "rocLovesC"
    packages { pf: "c-platform/main.roc" }
    imports []
    provides [main] to pf

main =
    expect 1 == 2
    "Roc <3 C!\n"
โฏ target/debug/roc dev examples/platform-switching/rocLovesC.roc
๐Ÿ”จ Rebuilding platform...

view this post on Zulip Ayaz Hafiz (Nov 09 2022 at 13:58):

what syscalls do you need to trace? strace isn't a thing on Mac, the two other options (dtruss and Instruments) have only ever hung and sigsegv'd for me over roc binaries

view this post on Zulip Folkert de Vries (Nov 09 2022 at 13:59):

ah, ok

view this post on Zulip Folkert de Vries (Nov 09 2022 at 14:00):

well, I'm assuming that the expect does fail, but the parent process just gets an empty buffer and hence prints nothing

view this post on Zulip Ayaz Hafiz (Nov 09 2022 at 15:01):

we can check what bytes expect is seeing before doing the printing. I can take a look later if you'd like

view this post on Zulip Folkert de Vries (Nov 09 2022 at 15:05):

I'll look at it with Richard too later today if you don't get to it before then

view this post on Zulip Folkert de Vries (Nov 09 2022 at 22:07):

@Ayaz Hafiz we didn't get to this, so if you can do some troubleshooting that would be great

view this post on Zulip Ayaz Hafiz (Nov 09 2022 at 22:18):

understood


Last updated: Jul 06 2025 at 12:14 UTC