From 47313f061e8c9c867288a9c6aeca38e81ff3a828 Mon Sep 17 00:00:00 2001 From: Daniel Heras Quesada Date: Tue, 28 Jan 2025 17:57:14 +0100 Subject: [PATCH] feat: cargo + testing --- Cargo.toml | 1 + src/bin/secondary_main.rs | 4 ++++ src/main.rs | 4 ++++ src/test/basic_test.rs | 14 ++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 src/bin/secondary_main.rs create mode 100644 src/test/basic_test.rs diff --git a/Cargo.toml b/Cargo.toml index 5496fc7..bdca37c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "rust-by-example" version = "0.1.0" edition = "2021" +default-run = "rust-by-example" [dependencies] # clap = "2.27.1" # from crates.io diff --git a/src/bin/secondary_main.rs b/src/bin/secondary_main.rs new file mode 100644 index 0000000..7310ecd --- /dev/null +++ b/src/bin/secondary_main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("This was ran with '$ cargo run --bin secondary_main'"); + println!("This is a secondary main!"); +} diff --git a/src/main.rs b/src/main.rs index 2c0d2df..1bf624d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,10 @@ // mod exercises; mod concepts; +#[cfg(test)] +#[path = "./test/basic_test.rs"] +mod test; + fn main() { // helloworld::hello_world_module(); // primitives::primitives_module(); diff --git a/src/test/basic_test.rs b/src/test/basic_test.rs new file mode 100644 index 0000000..7367791 --- /dev/null +++ b/src/test/basic_test.rs @@ -0,0 +1,14 @@ +#[cfg(test)] +pub mod tests { + #[test] + fn test_success() { + let my_hello = "Hello world!"; + assert_eq!(my_hello, "Hello world!"); + } + + #[test] + fn test_failure() { + let my_hello = "ef u world!"; + assert_eq!(my_hello, "Hello world!"); + } +}