Skip to content

Commit

Permalink
update all examples to basic-cli version and mark broken examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bhansconnect committed Nov 20, 2023
1 parent f727aea commit ffda01e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 48 deletions.
19 changes: 4 additions & 15 deletions crates/cli/tests/cli_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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"),
Expand All @@ -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());
}
Expand Down Expand Up @@ -866,7 +855,7 @@ mod cli_run {
&[],
&[],
&[],
"22424\n",
"30256\n",
UseValgrind::No,
TestCliCommands::Run,
)
Expand Down
6 changes: 3 additions & 3 deletions examples/cli/args.roc → examples/cli/argsBROKEN.roc
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -57,7 +57,7 @@ main =

Err helpMenu ->
{} <- Stdout.line helpMenu |> Task.await
Process.exit 1
Task.err 1

runCmd = \cmd ->
when cmd is
Expand Down
10 changes: 5 additions & 5 deletions examples/cli/countdown.roc
Original file line number Diff line number Diff line change
@@ -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 <ENTER>.")
_ <- await (Stdout.line "\nLet's count down from 3 together - all you have to do is press <ENTER>.")
_ <- 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))
14 changes: 9 additions & 5 deletions examples/cli/echo.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/env.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Binary file added examples/cli/file
Binary file not shown.
5 changes: 2 additions & 3 deletions examples/cli/file.roc → examples/cli/fileBROKEN.roc
Original file line number Diff line number Diff line change
@@ -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 },
Expand All @@ -12,7 +11,7 @@ app "file-io"
]
provides [main] to pf

main : Task {} []
main : Task {} I32
main =
path = Path.fromStr "out.txt"
task =
Expand Down Expand Up @@ -42,4 +41,4 @@ main =
_ -> "Uh oh, there was an error!"

{} <- Stderr.line msg |> Task.await
Process.exit 1
Task.err 1
12 changes: 10 additions & 2 deletions examples/cli/form.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
35 changes: 21 additions & 14 deletions examples/cli/http-get.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ffda01e

Please sign in to comment.