diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 98b6540034..8694cc0fad 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -474,18 +474,6 @@ mod cli_run { ) } - #[test] - #[serial(cli_platform)] - #[cfg_attr(windows, ignore)] - fn hello_world_no_url() { - test_roc_app_slim( - "examples", - "helloWorldNoURL.roc", - "Hello, World!\n", - UseValgrind::Yes, - ) - } - #[cfg(windows)] const LINE_ENDING: &str = "\r\n"; #[cfg(not(windows))] @@ -687,12 +675,13 @@ mod cli_run { } #[test] + #[ignore = "currently broken in basic-cli platform"] #[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")] #[serial(cli_platform)] fn cli_args() { test_roc_app( "examples/cli", - "args.roc", + "argsBROKEN.roc", &[], &[ Arg::PlainText("log"), @@ -713,7 +702,7 @@ mod cli_run { #[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")] #[serial(cli_platform)] fn cli_args_check() { - let path = file_path_from_root("examples/cli", "args.roc"); + let path = file_path_from_root("examples/cli", "argsBROKEN.roc"); let out = run_roc([CMD_CHECK, path.to_str().unwrap()], &[], &[]); assert!(out.status.success()); } @@ -866,7 +855,7 @@ mod cli_run { &[], &[], &[], - "22424\n", + "30256\n", UseValgrind::No, TestCliCommands::Run, ) diff --git a/examples/cli/args.roc b/examples/cli/argsBROKEN.roc similarity index 95% rename from examples/cli/args.roc rename to examples/cli/argsBROKEN.roc index 2ff4020a81..e5dc6ac8eb 100644 --- a/examples/cli/args.roc +++ b/examples/cli/argsBROKEN.roc @@ -1,9 +1,9 @@ app "args" packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.6.0/QOQW08n38nHHrVVkJNiPIjzjvbR3iMjXeFY5w1aT46w.tar.br" } - imports [pf.Stdout, pf.Arg, pf.Task.{ Task }, pf.Process] + imports [pf.Stdout, pf.Arg, pf.Task.{ Task }] provides [main] to pf -main : Task {} [] +main : Task {} I32 main = args <- Arg.list |> Task.await parser = @@ -57,7 +57,7 @@ main = Err helpMenu -> {} <- Stdout.line helpMenu |> Task.await - Process.exit 1 + Task.err 1 runCmd = \cmd -> when cmd is diff --git a/examples/cli/countdown.roc b/examples/cli/countdown.roc index 4b6f219013..f96624b40e 100644 --- a/examples/cli/countdown.roc +++ b/examples/cli/countdown.roc @@ -1,18 +1,18 @@ app "countdown" packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.6.0/QOQW08n38nHHrVVkJNiPIjzjvbR3iMjXeFY5w1aT46w.tar.br" } - imports [pf.Stdin, pf.Stdout, pf.Task.{ await, loop, succeed }] + imports [pf.Stdin, pf.Stdout, pf.Task.{ await, loop }] provides [main] to pf main = - _ <- await (Stdout.line "\nLet's count down from 10 together - all you have to do is press .") + _ <- await (Stdout.line "\nLet's count down from 3 together - all you have to do is press .") _ <- await Stdin.line - loop 10 tick + loop 3 tick tick = \n -> if n == 0 then _ <- await (Stdout.line "🎉 SURPRISE! Happy Birthday! 🎂") - succeed (Done {}) + Task.ok (Done {}) else _ <- await (n |> Num.toStr |> \s -> "\(s)..." |> Stdout.line) _ <- await Stdin.line - succeed (Step (n - 1)) + Task.ok (Step (n - 1)) diff --git a/examples/cli/echo.roc b/examples/cli/echo.roc index 67b8790777..5e744a9bac 100644 --- a/examples/cli/echo.roc +++ b/examples/cli/echo.roc @@ -3,15 +3,19 @@ app "echo" imports [pf.Stdin, pf.Stdout, pf.Task.{ Task }] provides [main] to pf -main : Task {} [] +main : Task {} I32 main = _ <- Task.await (Stdout.line "🗣 Shout into this cave and hear the echo! 👂👂👂") - Task.loop {} \_ -> Task.map tick Step -tick : Task.Task {} [] -tick = + Task.loop {} tick + +tick : {} -> Task [Step {}, Done {}] * +tick = \{} -> shout <- Task.await Stdin.line - Stdout.line (echo shout) + + when shout is + Input s -> Stdout.line (echo s) |> Task.map Step + End -> Stdout.line (echo "Received end of input (EOF).") |> Task.map Done echo : Str -> Str echo = \shout -> diff --git a/examples/cli/env.roc b/examples/cli/env.roc index bca4d6d663..73e9061e66 100644 --- a/examples/cli/env.roc +++ b/examples/cli/env.roc @@ -3,7 +3,7 @@ app "env" imports [pf.Stdout, pf.Stderr, pf.Env, pf.Task.{ Task }] provides [main] to pf -main : Task {} [] +main : Task {} I32 main = task = Env.decode "EDITOR" diff --git a/examples/cli/file b/examples/cli/file new file mode 100755 index 0000000000..5a46f8f73d Binary files /dev/null and b/examples/cli/file differ diff --git a/examples/cli/file.roc b/examples/cli/fileBROKEN.roc similarity index 95% rename from examples/cli/file.roc rename to examples/cli/fileBROKEN.roc index 81cff567e7..172ef73d9f 100644 --- a/examples/cli/file.roc +++ b/examples/cli/fileBROKEN.roc @@ -1,7 +1,6 @@ app "file-io" packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.6.0/QOQW08n38nHHrVVkJNiPIjzjvbR3iMjXeFY5w1aT46w.tar.br" } imports [ - pf.Process, pf.Stdout, pf.Stderr, pf.Task.{ Task }, @@ -12,7 +11,7 @@ app "file-io" ] provides [main] to pf -main : Task {} [] +main : Task {} I32 main = path = Path.fromStr "out.txt" task = @@ -42,4 +41,4 @@ main = _ -> "Uh oh, there was an error!" {} <- Stderr.line msg |> Task.await - Process.exit 1 + Task.err 1 diff --git a/examples/cli/form.roc b/examples/cli/form.roc index 90b8a281df..b5d397d7aa 100644 --- a/examples/cli/form.roc +++ b/examples/cli/form.roc @@ -3,10 +3,18 @@ app "form" imports [pf.Stdin, pf.Stdout, pf.Task.{ await, Task }] provides [main] to pf -main : Task {} [] +main : Task {} I32 main = _ <- 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)! 👋" + + Stdout.line "Hi, \(unwrap firstName) \(unwrap lastName)! 👋" + +unwrap : [Input Str, End] -> Str +unwrap = \input -> + when input is + Input line -> line + End -> "Received end of input (EOF)." diff --git a/examples/cli/http-get.roc b/examples/cli/http-get.roc index 7f63950725..4810ca2ce9 100644 --- a/examples/cli/http-get.roc +++ b/examples/cli/http-get.roc @@ -3,22 +3,29 @@ app "http-get" imports [pf.Http, pf.Task.{ Task }, pf.Stdin, pf.Stdout] provides [main] to pf -main : Task {} [] +main : Task {} I32 main = - _ <- Task.await (Stdout.line "Please enter a URL to fetch") + _ <- Task.await (Stdout.line "Enter a URL to fetch. It must contain a scheme like \"http://\" or \"https://\".") - url <- Task.await Stdin.line + input <- Task.await Stdin.line - request = { - method: Get, - headers: [], - url, - body: Http.emptyBody, - timeout: NoTimeout, - } + when input is + End -> + Stdout.line "I received end-of-input (EOF) instead of a URL." - output <- Http.send request - |> Task.onFail (\err -> err |> Http.errorToString |> Task.succeed) - |> Task.await + Input url -> + request = { + method: Get, + headers: [], + url, + body: Http.emptyBody, + timeout: NoTimeout, + } - Stdout.line output + output <- Http.send request + |> Task.onErr \err -> err + |> Http.errorToString + |> Task.ok + |> Task.await + + Stdout.line output