diff options
| author | Carlos Maiolino <[email protected]> | 2025-09-06 09:30:39 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-09-06 09:35:00 +0200 |
| commit | ee8a08bfa24d9a3d09273fdebe8d73ac38c545f9 (patch) | |
| tree | 856c1a6347bea7f29bf2048c8f2028e5a3e656ef | |
| parent | 93b1c04a218858ecc59b6b8929103695b7b8c2a0 (diff) | |
Update guessing game
Signed-off-by: Carlos Maiolino <[email protected]>
| -rw-r--r-- | rust/echor/.Cargo.toml.un~ | bin | 0 -> 4075 bytes | |||
| -rw-r--r-- | rust/echor/Cargo.lock | 362 | ||||
| -rw-r--r-- | rust/echor/Cargo.toml | 11 | ||||
| -rw-r--r-- | rust/echor/Cargo.toml~ | 8 | ||||
| -rw-r--r-- | rust/echor/err | 6 | ||||
| -rw-r--r-- | rust/echor/out | 0 | ||||
| -rw-r--r-- | rust/echor/src/.main.rs.un~ | bin | 0 -> 82832 bytes | |||
| -rw-r--r-- | rust/echor/src/main.rs | 34 | ||||
| -rw-r--r-- | rust/echor/src/main.rs~ | 34 | ||||
| -rw-r--r-- | rust/echor/tests/.cli.rs.un~ | bin | 0 -> 10463 bytes | |||
| -rw-r--r-- | rust/echor/tests/cli.rs | 27 | ||||
| -rw-r--r-- | rust/echor/tests/cli.rs~ | 26 | ||||
| -rw-r--r-- | rust/echor/tests/expected/hello1.txt | 1 | ||||
| -rw-r--r-- | rust/guessing_game/src/main.rs | 32 | ||||
| -rw-r--r-- | rust/hello/Cargo.lock | 128 | ||||
| -rw-r--r-- | rust/hello/Cargo.toml | 7 | ||||
| -rw-r--r-- | rust/hello/false.core | bin | 0 -> 12189696 bytes | |||
| -rw-r--r-- | rust/hello/src/bin/false.rs | 4 | ||||
| -rw-r--r-- | rust/hello/src/bin/true.rs | 3 | ||||
| -rw-r--r-- | rust/hello/src/main.rs | 3 | ||||
| -rw-r--r-- | rust/hello/tests/.cli.rs.un~ | bin | 0 -> 1045 bytes | |||
| -rw-r--r-- | rust/hello/tests/cli.rs | 19 | ||||
| -rw-r--r-- | rust/hello/tests/cli.rs~ | 19 |
23 files changed, 714 insertions, 10 deletions
diff --git a/rust/echor/.Cargo.toml.un~ b/rust/echor/.Cargo.toml.un~ Binary files differnew file mode 100644 index 0000000..0471b80 --- /dev/null +++ b/rust/echor/.Cargo.toml.un~ diff --git a/rust/echor/Cargo.lock b/rust/echor/Cargo.lock new file mode 100644 index 0000000..4413c3d --- /dev/null +++ b/rust/echor/Cargo.lock @@ -0,0 +1,362 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "anstyle" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "assert_cmd" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bd389a4b2970a01282ee455294913c0a43724daedcd1a24c3eb0ec1c1320b66" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "libc", + "predicates 3.1.3", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bstr" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "echor" +version = "0.1.0" +dependencies = [ + "assert_cmd", + "clap", + "predicates 2.1.5", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "predicates" +version = "2.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" +dependencies = [ + "difflib", + "float-cmp", + "itertools", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa" + +[[package]] +name = "predicates-tree" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termtree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/rust/echor/Cargo.toml b/rust/echor/Cargo.toml new file mode 100644 index 0000000..8be4896 --- /dev/null +++ b/rust/echor/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "echor" +version = "0.1.0" +edition = "2024" + +[dependencies] +clap = "2.33" + +[dev-dependencies] +assert_cmd = "2" +predicates = "2" diff --git a/rust/echor/Cargo.toml~ b/rust/echor/Cargo.toml~ new file mode 100644 index 0000000..8ee6386 --- /dev/null +++ b/rust/echor/Cargo.toml~ @@ -0,0 +1,8 @@ +[package] +name = "echor" +version = "0.1.0" +edition = "2024" + +[dependencies] +clap = "2.33" +assert_cmd = "2" diff --git a/rust/echor/err b/rust/echor/err new file mode 100644 index 0000000..0e9603b --- /dev/null +++ b/rust/echor/err @@ -0,0 +1,6 @@ +error: Found argument '-y' which wasn't expected, or isn't valid in this context + +USAGE: + echor [FLAGS] <TEXT>... + +For more information try --help diff --git a/rust/echor/out b/rust/echor/out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/rust/echor/out diff --git a/rust/echor/src/.main.rs.un~ b/rust/echor/src/.main.rs.un~ Binary files differnew file mode 100644 index 0000000..b993ba5 --- /dev/null +++ b/rust/echor/src/.main.rs.un~ diff --git a/rust/echor/src/main.rs b/rust/echor/src/main.rs new file mode 100644 index 0000000..323d4c7 --- /dev/null +++ b/rust/echor/src/main.rs @@ -0,0 +1,34 @@ +use clap::{App, Arg}; + +/* + * Lack of specified return value means the function will return an UNIT type + */ +fn main() { + let matches = App::new("echor") + .version("0.1.0") + .author("Ronaldo curintiano") + .about("echo rusty") + .arg( + Arg::with_name("text") + .value_name("TEXT") + .help("Input text") + .required(true) + .min_values(1), + ) + .arg( + Arg::with_name("omit_newline") + .value_name("OMIT NEWLINE") + .short("n") + .help("Do not print newline") + .takes_value(false), + ) + .get_matches(); + + let text = matches.values_of_lossy("text").unwrap().join(" "); + let omit_newline :bool = matches.is_present("omit_newline"); + + print!("{}{}", + text, + if omit_newline {""} else {"\n"}); + +} diff --git a/rust/echor/src/main.rs~ b/rust/echor/src/main.rs~ new file mode 100644 index 0000000..fc2d607 --- /dev/null +++ b/rust/echor/src/main.rs~ @@ -0,0 +1,34 @@ +use clap::{App, Arg}; + +/* + * Lack of specified return value means the function will return an UNIT type + */ +fn main() { + let matches = App::new("echor") + .version("0.1.0") + .author("Ronaldo curintiano") + .about("echo rusty") + .arg( + Arg::with_name("text") + .value_name("TEXT") + .help("Input text") + .required(true) + .min_values(1), + ) + .arg( + Arg::with_name("omit_newline") + .value_name("OMIT NEWLINE") + .short("n") + .help("Do not print newline") + .takes_value(false), + ) + .get_matches(); + + let text = matches.values_of_lossy("text").unwrap().join(" "); + let omit_newline :bool = matches.is_present("omit_newline"); + + print("{}{}", + text, + if omit_newline {""} else {"\n"}); + +} diff --git a/rust/echor/tests/.cli.rs.un~ b/rust/echor/tests/.cli.rs.un~ Binary files differnew file mode 100644 index 0000000..7a6e081 --- /dev/null +++ b/rust/echor/tests/.cli.rs.un~ diff --git a/rust/echor/tests/cli.rs b/rust/echor/tests/cli.rs new file mode 100644 index 0000000..e78eb36 --- /dev/null +++ b/rust/echor/tests/cli.rs @@ -0,0 +1,27 @@ +use assert_cmd::Command; +use predicates::prelude::*; +use std::fs; + +#[test] +fn dies_no_args() { + let mut cmd = Command::cargo_bin("echor").unwrap(); + cmd.assert() + .failure() + .stderr(predicate::str::contains("USAGE")); +} + +#[test] +fn runs() { + let mut cmd = Command::cargo_bin("echor").unwrap(); + cmd.arg("Howdy partner").assert().success(); +} + +#[test] +fn hello1() { + let expected = fs::read_to_string("tests/expected/hello1.txt").unwrap(); + let mut cmd = Command::cargo_bin("echor").unwrap(); + cmd.arg("Hello there") + .assert() + .success() + .stdout(expected); +} diff --git a/rust/echor/tests/cli.rs~ b/rust/echor/tests/cli.rs~ new file mode 100644 index 0000000..d6e32b1 --- /dev/null +++ b/rust/echor/tests/cli.rs~ @@ -0,0 +1,26 @@ +use assert_cmd::Command; +use predicates::prelude::*; + +#[test] +fn dies_no_args() { + let mut cmd = Command::cargo_bin("echor").unwrap(); + cmd.assert() + .failure() + .stderr(predicate::str::contains("USAGE")); +} + +#[test] +fn runs() { + let mut cmd = Command::cargo_bin("echor").unwrap(); + cmd.arg("Howdy partner").assert().success(); +} + +#[test] +fn hello1() { + let expected = fs::read_to_string("tests/expected/hello1.txt").unwrap(); + let mut cmd = Command::cargo_bin("echor").unwrap(); + cmd.arg("Hello there") + .assert() + .success() + .stdout(expected); +} diff --git a/rust/echor/tests/expected/hello1.txt b/rust/echor/tests/expected/hello1.txt new file mode 100644 index 0000000..d6613f5 --- /dev/null +++ b/rust/echor/tests/expected/hello1.txt @@ -0,0 +1 @@ +Hello there diff --git a/rust/guessing_game/src/main.rs b/rust/guessing_game/src/main.rs index 7c6fea3..8e038a8 100644 --- a/rust/guessing_game/src/main.rs +++ b/rust/guessing_game/src/main.rs @@ -1,25 +1,33 @@ -use rand::Rng; use std::cmp::Ordering; use std::io; +use rand::Rng; + fn main() { - println!("Guess the number!"); + println!("Guess the number"); let secret_number = rand::thread_rng().gen_range(1..=100); + let mut tries = 10; loop { - println!("Please input your guess."); - let mut guess = String::new(); + if tries == 0 { + println!("You guessed wrong for the last time... You LOSE!"); + break; + } + println!("Please input your guess: "); + let mut guess = String::new(); io::stdin() - .read_line(&mut guess) // Returns a 'Result' type + .read_line(&mut guess) .expect("Failed to read line"); - // /- Returns a Result type let guess: u32 = match guess.trim().parse() { - Ok(num) => num, - Err(_) => continue, + Ok(n) => n, + Err(_) => { + println!("Invalid guess... Please type a number..."); + continue; + }, }; println!("You guessed: {guess}"); @@ -30,7 +38,11 @@ fn main() { Ordering::Equal => { println!("You win!"); break; - } // Code block executed if match hits ::Equal - }; + }, + } + + tries -= 1; + println!("Attempts left: {tries}"); } + return; } diff --git a/rust/hello/Cargo.lock b/rust/hello/Cargo.lock new file mode 100644 index 0000000..577ea0a --- /dev/null +++ b/rust/hello/Cargo.lock @@ -0,0 +1,128 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "assert_cmd" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c98233c6673d8601ab23e77eb38f999c51100d46c5703b17288c57fddf3a1ffe" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "hello" +version = "0.1.0" +dependencies = [ + "assert_cmd", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "predicates" +version = "2.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" +dependencies = [ + "difflib", + "itertools", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa" + +[[package]] +name = "predicates-tree" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + +[[package]] +name = "termtree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" + +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] diff --git a/rust/hello/Cargo.toml b/rust/hello/Cargo.toml new file mode 100644 index 0000000..6f29c28 --- /dev/null +++ b/rust/hello/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "hello" +version = "0.1.0" +edition = "2024" + +[dependencies] +assert_cmd = "1" diff --git a/rust/hello/false.core b/rust/hello/false.core Binary files differnew file mode 100644 index 0000000..8f68c3a --- /dev/null +++ b/rust/hello/false.core diff --git a/rust/hello/src/bin/false.rs b/rust/hello/src/bin/false.rs new file mode 100644 index 0000000..a0d6817 --- /dev/null +++ b/rust/hello/src/bin/false.rs @@ -0,0 +1,4 @@ +fn main() { + //std::process::exit(1); + std::process::abort(); +} diff --git a/rust/hello/src/bin/true.rs b/rust/hello/src/bin/true.rs new file mode 100644 index 0000000..44490fa --- /dev/null +++ b/rust/hello/src/bin/true.rs @@ -0,0 +1,3 @@ +fn main() { + std::process::exit(0); +} diff --git a/rust/hello/src/main.rs b/rust/hello/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/rust/hello/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/rust/hello/tests/.cli.rs.un~ b/rust/hello/tests/.cli.rs.un~ Binary files differnew file mode 100644 index 0000000..9dee229 --- /dev/null +++ b/rust/hello/tests/.cli.rs.un~ diff --git a/rust/hello/tests/cli.rs b/rust/hello/tests/cli.rs new file mode 100644 index 0000000..a69010f --- /dev/null +++ b/rust/hello/tests/cli.rs @@ -0,0 +1,19 @@ +use assert_cmd::Command; + +#[test] +fn runs() { + let mut cmd = Command::cargo_bin("hello").unwrap(); + cmd.assert().success().stdout("Hello, world!\n"); +} + +#[test] +fn true_ok() { + let mut cmd = Command::cargo_bin("true").unwrap(); + cmd.assert().success(); +} + +#[test] +fn false_not_ok() { + let mut cmd = Command::cargo_bin("false").unwrap(); + cmd.assert().failure(); +} diff --git a/rust/hello/tests/cli.rs~ b/rust/hello/tests/cli.rs~ new file mode 100644 index 0000000..57bbfdf --- /dev/null +++ b/rust/hello/tests/cli.rs~ @@ -0,0 +1,19 @@ +use assert_cmd::Command; + +#[test] +fn runs() { + let mut cmd = Command::cargo_bin("hello").unwrap(); + cmd.assert().success().stdout("Hello, world!!\n"); +} + +#[test] +fn true_ok() { + let mut cmd = Command::cargo_bin("true").unwrap(); + cmd.assert().success(); +} + +#[test] +fn false_not_ok() { + let mut cmd = Command::cargo_bin("false").unwrap(); + cmd.assert().failure(); +} |
