diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 7db8f33f69..d541e2ea4e 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -491,7 +491,7 @@ mod cli_run { // expected_ending: "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", // use_valgrind: true, // }, - args:"interactive" => Example { + cli_args:"interactive" => Example { filename: "args.roc", executable_filename: "args", stdin: &[], @@ -507,7 +507,7 @@ mod cli_run { expected_ending: "hi there!\nIt is known\n", use_valgrind: true, }, - // tea:"tea" => Example { + // tui_tea:"tea" => Example { // filename: "Main.roc", // executable_filename: "tea-example", // stdin: &[], @@ -515,7 +515,7 @@ mod cli_run { // expected_ending: "", // use_valgrind: true, // }, - cli:"interactive" => Example { + cli_form:"interactive" => Example { filename: "form.roc", executable_filename: "form", stdin: &["Giovanni\n", "Giorgio\n"], @@ -967,23 +967,50 @@ mod cli_run { &[], indoc!( r#" - ── UNRECOGNIZED NAME ─────────────────────────── tests/known_bad/TypeError.roc ─ + ── TYPE MISMATCH ─ ...d/../../../../examples/interactive/cli-platform/main.roc ─ - Nothing is named `d` in this scope. + Something is off with the type annotation of the main required symbol: - 10│ _ <- await (line d) - ^ + 2│ requires {} { main : InternalProgram } + ^^^^^^^^^^^^^^^ - Did you mean one of these? + This #UserApp.main value is a: - U8 - Ok - I8 - F64 + Task.Task {} * [Write [Stdout]*]* ? + + But the type annotation on main says it should be: + + InternalProgram.InternalProgram ? + + Tip: Type comparisons between an opaque type are only ever equal if + both types are the same opaque type. Did you mean to create an opaque + type by wrapping it? If I have an opaque type Age := U32 I can create + an instance of this opaque type by doing @Age 23. + + + ── TYPE MISMATCH ─ ...d/../../../../examples/interactive/cli-platform/main.roc ─ + + This 1st argument to toEffect has an unexpected type: + + 9│ mainForHost = InternalProgram.toEffect main + ^^^^ + + This #UserApp.main value is a: + + Task.Task {} * [Write [Stdout]*]* ? + + But toEffect needs its 1st argument to be: + + InternalProgram.InternalProgram ? + + Tip: Type comparisons between an opaque type are only ever equal if + both types are the same opaque type. Did you mean to create an opaque + type by wrapping it? If I have an opaque type Age := U32 I can create + an instance of this opaque type by doing @Age 23. ──────────────────────────────────────────────────────────────────────────────── - 1 error and 0 warnings found in ms."# + 2 errors and 1 warning found in ms."# ), ); } diff --git a/crates/cli/tests/known_bad/TypeError.roc b/crates/cli/tests/known_bad/TypeError.roc index 2eaec83ae7..fa6060e81a 100644 --- a/crates/cli/tests/known_bad/TypeError.roc +++ b/crates/cli/tests/known_bad/TypeError.roc @@ -1,11 +1,13 @@ app "type-error" packages { pf: "../../../../examples/interactive/cli-platform/main.roc" } - imports [pf.Stdout.{ line }, pf.Task.{ await }] + imports [pf.Stdout.{ line }, pf.Task.{ await }, pf.Program] provides [main] to pf -main = \_args -> +main = _ <- await (line "a") _ <- await (line "b") _ <- await (line "c") - _ <- await (line d) + _ <- await (line "d") line "e" + # Type mismatch because this line is missing: + # |> Program.quick diff --git a/examples/interactive/args.roc b/examples/interactive/args.roc index bdab831686..97cb8ca8cc 100644 --- a/examples/interactive/args.roc +++ b/examples/interactive/args.roc @@ -1,10 +1,10 @@ app "args" packages { pf: "cli-platform/main.roc" } - imports [pf.Stdout, pf.Task, pf.Arg] + imports [pf.Stdout, pf.Arg, pf.Program.{ Program }] provides [main] to pf -main : List Str -> Task.Task {} [] [Write [Stdout]] -main = \args -> +main : Program +main = Program.withArgs \args -> parser = divCmd = Arg.succeed (\dividend -> \divisor -> Div (Num.toF64 dividend) (Num.toF64 divisor)) @@ -49,9 +49,15 @@ main = \args -> |> Arg.program { name: "args-example", help: "A calculator example of the CLI platform argument parser" } when Arg.parseFormatted parser args is - Ok cmd -> runCmd cmd |> Num.toStr |> Stdout.line + Ok cmd -> + runCmd cmd + |> Num.toStr + |> Stdout.line + |> Program.exit 0 + Err helpMenu -> Stdout.line helpMenu + |> Program.exit 1 runCmd = \cmd -> when cmd is diff --git a/examples/interactive/echo.roc b/examples/interactive/echo.roc index d6c225a76a..c44bcbabbf 100644 --- a/examples/interactive/echo.roc +++ b/examples/interactive/echo.roc @@ -1,12 +1,16 @@ app "echo" packages { pf: "cli-platform/main.roc" } - imports [pf.Stdin, pf.Stdout, pf.Task] + imports [pf.Stdin, pf.Stdout, pf.Task.{ Task }, pf.Program.{ Program, ExitCode }] provides [main] to pf -main : List Str -> Task.Task {} [] [Read [Stdin], Write [Stdout]] -main = \_args -> +main : Program +main = Program.noArgs mainTask + +mainTask : List Str -> Task ExitCode [] [Read [Stdin], Write [Stdout]] +mainTask = \_args -> _ <- Task.await (Stdout.line "🗣 Shout into this cave and hear the echo! 👂👂👂") Task.loop {} (\_ -> Task.map tick Step) + |> Program.exit 0 tick : Task.Task {} [] [Read [Stdin]*, Write [Stdout]*]* tick = diff --git a/examples/interactive/form.roc b/examples/interactive/form.roc index 9e8d7c46fb..5df943c514 100644 --- a/examples/interactive/form.roc +++ b/examples/interactive/form.roc @@ -1,12 +1,16 @@ app "form" packages { pf: "cli-platform/main.roc" } - imports [pf.Stdin, pf.Stdout, pf.Task.{ await, Task }] + imports [pf.Stdin, pf.Stdout, pf.Task.{ await, Task }, pf.Program.{ Program, ExitCode }] provides [main] to pf -main : List Str -> Task {} * [Read [Stdin], Write [Stdout]] -main = \_args -> +main : Program +main = Program.noArgs mainTask + +mainTask : Task ExitCode [] [Read [Stdin], Write [Stdout]] +mainTask = _ <- await (Stdout.line "What's your first name?") firstName <- await Stdin.line _ <- await (Stdout.line "What's your last name?") lastName <- await Stdin.line Stdout.line "Hi, \(firstName) \(lastName)! 👋" + |> Program.exit 0