update all examples to basic-cli version and mark broken examples

This commit is contained in:
Brendan Hansknecht 2023-11-20 15:36:15 -08:00
parent f727aea875
commit ffda01e80b
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
9 changed files with 55 additions and 48 deletions

View file

@ -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)] #[cfg(windows)]
const LINE_ENDING: &str = "\r\n"; const LINE_ENDING: &str = "\r\n";
#[cfg(not(windows))] #[cfg(not(windows))]
@ -687,12 +675,13 @@ mod cli_run {
} }
#[test] #[test]
#[ignore = "currently broken in basic-cli platform"]
#[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")] #[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")]
#[serial(cli_platform)] #[serial(cli_platform)]
fn cli_args() { fn cli_args() {
test_roc_app( test_roc_app(
"examples/cli", "examples/cli",
"args.roc", "argsBROKEN.roc",
&[], &[],
&[ &[
Arg::PlainText("log"), Arg::PlainText("log"),
@ -713,7 +702,7 @@ mod cli_run {
#[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")] #[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")]
#[serial(cli_platform)] #[serial(cli_platform)]
fn cli_args_check() { 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()], &[], &[]); let out = run_roc([CMD_CHECK, path.to_str().unwrap()], &[], &[]);
assert!(out.status.success()); assert!(out.status.success());
} }
@ -866,7 +855,7 @@ mod cli_run {
&[], &[],
&[], &[],
&[], &[],
"22424\n", "30256\n",
UseValgrind::No, UseValgrind::No,
TestCliCommands::Run, TestCliCommands::Run,
) )

View file

@ -1,9 +1,9 @@
app "args" app "args"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.6.0/QOQW08n38nHHrVVkJNiPIjzjvbR3iMjXeFY5w1aT46w.tar.br" } 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 provides [main] to pf
main : Task {} [] main : Task {} I32
main = main =
args <- Arg.list |> Task.await args <- Arg.list |> Task.await
parser = parser =
@ -57,7 +57,7 @@ main =
Err helpMenu -> Err helpMenu ->
{} <- Stdout.line helpMenu |> Task.await {} <- Stdout.line helpMenu |> Task.await
Process.exit 1 Task.err 1
runCmd = \cmd -> runCmd = \cmd ->
when cmd is when cmd is

View file

@ -1,18 +1,18 @@
app "countdown" app "countdown"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.6.0/QOQW08n38nHHrVVkJNiPIjzjvbR3iMjXeFY5w1aT46w.tar.br" } 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 provides [main] to pf
main = 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 _ <- await Stdin.line
loop 10 tick loop 3 tick
tick = \n -> tick = \n ->
if n == 0 then if n == 0 then
_ <- await (Stdout.line "🎉 SURPRISE! Happy Birthday! 🎂") _ <- await (Stdout.line "🎉 SURPRISE! Happy Birthday! 🎂")
succeed (Done {}) Task.ok (Done {})
else else
_ <- await (n |> Num.toStr |> \s -> "\(s)..." |> Stdout.line) _ <- await (n |> Num.toStr |> \s -> "\(s)..." |> Stdout.line)
_ <- await Stdin.line _ <- await Stdin.line
succeed (Step (n - 1)) Task.ok (Step (n - 1))

View file

@ -3,15 +3,19 @@ app "echo"
imports [pf.Stdin, pf.Stdout, pf.Task.{ Task }] imports [pf.Stdin, pf.Stdout, pf.Task.{ Task }]
provides [main] to pf provides [main] to pf
main : Task {} [] main : Task {} I32
main = main =
_ <- Task.await (Stdout.line "🗣 Shout into this cave and hear the echo! 👂👂👂") _ <- Task.await (Stdout.line "🗣 Shout into this cave and hear the echo! 👂👂👂")
Task.loop {} \_ -> Task.map tick Step
tick : Task.Task {} [] Task.loop {} tick
tick =
tick : {} -> Task [Step {}, Done {}] *
tick = \{} ->
shout <- Task.await Stdin.line 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 : Str -> Str
echo = \shout -> echo = \shout ->

View file

@ -3,7 +3,7 @@ app "env"
imports [pf.Stdout, pf.Stderr, pf.Env, pf.Task.{ Task }] imports [pf.Stdout, pf.Stderr, pf.Env, pf.Task.{ Task }]
provides [main] to pf provides [main] to pf
main : Task {} [] main : Task {} I32
main = main =
task = task =
Env.decode "EDITOR" Env.decode "EDITOR"

BIN
examples/cli/file Executable file

Binary file not shown.

View file

@ -1,7 +1,6 @@
app "file-io" app "file-io"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.6.0/QOQW08n38nHHrVVkJNiPIjzjvbR3iMjXeFY5w1aT46w.tar.br" } packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.6.0/QOQW08n38nHHrVVkJNiPIjzjvbR3iMjXeFY5w1aT46w.tar.br" }
imports [ imports [
pf.Process,
pf.Stdout, pf.Stdout,
pf.Stderr, pf.Stderr,
pf.Task.{ Task }, pf.Task.{ Task },
@ -12,7 +11,7 @@ app "file-io"
] ]
provides [main] to pf provides [main] to pf
main : Task {} [] main : Task {} I32
main = main =
path = Path.fromStr "out.txt" path = Path.fromStr "out.txt"
task = task =
@ -42,4 +41,4 @@ main =
_ -> "Uh oh, there was an error!" _ -> "Uh oh, there was an error!"
{} <- Stderr.line msg |> Task.await {} <- Stderr.line msg |> Task.await
Process.exit 1 Task.err 1

View file

@ -3,10 +3,18 @@ app "form"
imports [pf.Stdin, pf.Stdout, pf.Task.{ await, Task }] imports [pf.Stdin, pf.Stdout, pf.Task.{ await, Task }]
provides [main] to pf provides [main] to pf
main : Task {} [] main : Task {} I32
main = main =
_ <- await (Stdout.line "What's your first name?") _ <- await (Stdout.line "What's your first name?")
firstName <- await Stdin.line firstName <- await Stdin.line
_ <- await (Stdout.line "What's your last name?") _ <- await (Stdout.line "What's your last name?")
lastName <- await Stdin.line 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)."

View file

@ -3,22 +3,29 @@ app "http-get"
imports [pf.Http, pf.Task.{ Task }, pf.Stdin, pf.Stdout] imports [pf.Http, pf.Task.{ Task }, pf.Stdin, pf.Stdout]
provides [main] to pf provides [main] to pf
main : Task {} [] main : Task {} I32
main = 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 = { when input is
method: Get, End ->
headers: [], Stdout.line "I received end-of-input (EOF) instead of a URL."
url,
body: Http.emptyBody,
timeout: NoTimeout,
}
output <- Http.send request Input url ->
|> Task.onFail (\err -> err |> Http.errorToString |> Task.succeed) request = {
|> Task.await 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