diff --git a/.github/workflows/audit-check.yml b/.github/workflows/audit-check.yml index bb021f2..df59bd9 100644 --- a/.github/workflows/audit-check.yml +++ b/.github/workflows/audit-check.yml @@ -1,8 +1,7 @@ name: Security audit on: - # TODO re-enable once project is set up properly - #push: + push: #schedule: # - cron: '0 0 * * *' workflow_dispatch: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffcc46d..a794d83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,7 @@ name: CI on: - # TODO re-enable once project is set up properly - #push: + push: workflow_dispatch: env: @@ -14,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - all-features: [ false ] # TODO if your crate has optional features, add 'true' to this list + all-features: [ false, true ] runs-on: ubuntu-latest steps: - name: Checkout code @@ -55,9 +54,9 @@ jobs: strategy: fail-fast: false matrix: - toolchain: [ 1.60.0 ] # TODO: change for your minimum supported Rust version + toolchain: [ 1.56.1 ] os: [ ubuntu, macos, windows ] - all-features: [ false ] # TODO if your crate has optional features, add 'true' to this list + all-features: [ false, true ] runs-on: ${{ matrix.os }}-latest steps: - name: Checkout code @@ -95,10 +94,10 @@ jobs: strategy: fail-fast: false matrix: - toolchain: [ 1.68.2, stable, beta, nightly ] # TODO: change 1.68.2 for your minimum supported Rust version + toolchain: [ 1.65.0, stable, beta, nightly ] os: [ ubuntu, macos, windows ] ignore-lock: [ false, true ] - all-features: [ false ] # TODO if your crate has optional features, add 'true' to this list + all-features: [ false, true ] include: - experimental: false - toolchain: beta diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..12b251c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,369 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if", + "hashbrown", + "lock_api", + "once_cell", + "parking_lot_core", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rust-template-output" +version = "0.1.0" +dependencies = [ + "either", + "rustc_version", + "serial_test", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serial_test" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ad9342b3aaca7cb43c45c097dd008d4907070394bd0751a0aa8817e5a018d" +dependencies = [ + "dashmap", + "futures", + "lazy_static", + "log", + "parking_lot", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b93fb4adc70021ac1b47f7d45e8cc4169baaa7ea58483bc5b721d19a26202212" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..47189f1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "rust-template-output" +version = "0.1.0" +edition = "2021" +default-run = "rust-template-output" + +[features] +test_feature_1 = [] + +[dependencies] +either = "1.6.0" + +[dev-dependencies] +serial_test = "3.0.0" + +[build-dependencies] +rustc_version = "0.4.0" diff --git a/Cargo.toml.msrv b/Cargo.toml.msrv new file mode 100644 index 0000000..dc53c94 --- /dev/null +++ b/Cargo.toml.msrv @@ -0,0 +1,14 @@ +[package] +name = "rust-template-output" +version = "0.1.0" +edition = "2021" +default-run = "rust-template-output" + +[features] +test_feature_1 = [] + +[dependencies] +either = "1.6.0" + +[build-dependencies] +rustc_version = "0.4.0" 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..3c83334 --- /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 hello_str = "hello"; + assert!(!hello_str.is_empty()); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..0e5a501 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,80 @@ +//! A simple lib crate to test the `rust-template`. + +use std::iter; + +use either::Either; + +/// Returns hello string +/// +/// ``` +/// use rust_template_output::hello; +/// +/// let hello_str = hello(); +/// assert!(!hello_str.is_empty()); +/// ``` +pub fn hello() -> &'static str { + "Hello, World!" +} + +/// Returns a string for feature! +/// +/// ``` +/// use rust_template_output::for_feature; +/// +/// let feature_str = for_feature(); +/// assert!(!feature_str.is_empty()); +/// ``` +#[cfg(feature = "test_feature_1")] +pub fn for_feature() -> &'static str { + "For feature!" +} + +/// Returns an iterator with either one or no item. +/// +/// ``` +/// use rust_template_output::iterate_maybe; +/// +/// let mut it = iterate_maybe(Some("hello!")); +/// assert_eq!(Some("hello!"), it.next()); +/// assert_eq!(None, it.next()); +/// +/// let mut it = iterate_maybe::<&str>(None); +/// assert_eq!(None, it.next()); +/// ``` +pub fn iterate_maybe(value: Option) -> impl Iterator { + match value { + Some(value) => Either::Left(iter::once(value)), + None => Either::Right(iter::empty()), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_lib_one() { + let hello_str = hello(); + assert!(!hello_str.is_empty()); + } + + #[cfg(feature = "test_feature_1")] + mod for_feature { + use super::*; + + #[test] + fn test_for_feature_one() { + let feature_str = for_feature(); + assert!(!feature_str.is_empty()); + } + } + + #[test] + fn test_iterate_maybe() { + let v: Vec<_> = iterate_maybe(Some(42)).collect(); + assert_eq!(vec![42], v); + + let v: Vec = iterate_maybe(None).collect(); + assert!(v.is_empty()); + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9d22219 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,30 @@ +use rust_template_output::{hello, iterate_maybe}; + +fn main() { + println!("{}", hello()); + + if cfg!(feature = "test_feature_1") { + println!("test-feature-1 is enabled"); + } else { + println!("test-feature-1 is disabled"); + } + + let v: Vec<_> = iterate_maybe(Some("Hello, World!")).collect(); + if let Some(&s) = v.first() { + println!("{}", s); + } + + let v: Vec<&str> = iterate_maybe(None).collect(); + if let Some(&s) = v.first() { + println!("{}", s); + } +} + +#[cfg(test)] +mod tests { + #[test] + fn test_main_one() { + let hello_str = "hello"; + assert!(!hello_str.is_empty()); + } +} diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs new file mode 100644 index 0000000..e66baec --- /dev/null +++ b/tests/integration_tests.rs @@ -0,0 +1,22 @@ +use rust_template_output::{hello, iterate_maybe}; +use serial_test::serial; + +#[test] +fn test_integration_one() { + let hello_str = hello(); + assert!(!hello_str.is_empty()); +} + +#[test] +#[serial] +fn test_iterate_one() { + let v: Vec<_> = iterate_maybe(Some(42)).collect(); + assert_eq!(vec![42], v); +} + +#[test] +#[serial] +fn test_iterate_none() { + let v: Vec = iterate_maybe(None).collect(); + assert!(v.is_empty()); +}