diff --git a/Cargo.toml b/Cargo.toml index c082421..92d2ad6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "rust-template-output" version = "0.1.0" edition = "2021" +default-run = "rust-template-output" [features] test_feature_1 = [] diff --git a/build.rs b/build.rs index 6fe9f5b..45a1acc 100644 --- a/build.rs +++ b/build.rs @@ -1,15 +1,14 @@ use std::env; -// use rustc_version::version_meta; -// use rustc_version::Channel::Nightly; +use rustc_version::version_meta; +use rustc_version::Channel::Nightly; fn main() { println!("cargo:rerun-if-env-changed=CI"); - // Uncomment this to be notified when we're building on Nightly toolset - // if version_meta().unwrap().channel <= Nightly { - // println!("cargo:rustc-cfg=nightly_rustc"); - // } + if version_meta().unwrap().channel <= Nightly { + println!("cargo:rustc-cfg=nightly_rustc"); + } // On CI, do not run integration tests. if env::var("CI").is_ok() { diff --git a/src/bin/bin_1.rs b/src/bin/bin_1.rs new file mode 100644 index 0000000..a4679ee --- /dev/null +++ b/src/bin/bin_1.rs @@ -0,0 +1,14 @@ +use rust_template_output::hello; + +fn main() { + println!("{} (from bin_1)", hello()); +} + +#[cfg(test)] +mod tests { + #[test] + fn test_bin_1_one() { + let foo = "foo"; + assert!(!foo.is_empty()); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d827a4b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,22 @@ +/// Returns hello string +/// +/// ``` +/// use rust_template_output::hello; +/// +/// let foo = hello(); +/// assert!(!foo.is_empty()); +/// ``` +pub fn hello() -> &'static str { + "Hello, World!" +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_lib_one() { + let foo = hello(); + assert!(!foo.is_empty()); + } +} diff --git a/src/main.rs b/src/main.rs index e1bc5a8..e143364 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ +use rust_template_output::hello; + fn main() { - println!("Hello, world!"); + println!("{}", hello()); if cfg!(feature = "test_feature_1") { println!("test-feature-1 is enabled"); @@ -7,3 +9,12 @@ fn main() { println!("test-feature-1 is disabled"); } } + +#[cfg(test)] +mod tests { + #[test] + fn test_main_one() { + let foo = "foo"; + assert!(!foo.is_empty()); + } +} diff --git a/tarpaulin.toml b/tarpaulin.toml index 5b95ab2..f1afab6 100644 --- a/tarpaulin.toml +++ b/tarpaulin.toml @@ -2,6 +2,6 @@ workspace = true all-features = true engine = "Llvm" -exclude-files = [ "target*/*" ] +exclude-files = [ "target*/*", "src/main.rs", "src/bin/*" ] run-types = [ "Tests" ] out = [ "Html", "Xml" ] diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs new file mode 100644 index 0000000..6785ee8 --- /dev/null +++ b/tests/integration_tests.rs @@ -0,0 +1,7 @@ +use rust_template_output::hello; + +#[test] +fn test_integration_one() { + let foo = hello(); + assert!(!foo.is_empty()); +}