From 3824bd2b0f1ccf2aa3e791f79c065ed62feaa170 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 3 Jan 2024 04:04:57 +0100 Subject: [PATCH] More tests --- micronfig_macros/src/lib.rs | 18 ++++++----- .../tests/sources/chain_single_down.rs | 7 ++++ .../tests/sources/chain_single_up.rs | 7 ++++ .../tests/sources/example_patchedporobot.rs | 0 .../tests/sources/from_single_custom.rs | 16 ++++++++++ .../tests/sources/parse_single_custom.rs | 18 +++++++++++ .../tests/sources/parse_single_ipaddr.rs | 7 ---- ...athbuf_full.rs => parse_single_pathbuf.rs} | 0 .../tests/sources/tryfrom_single_custom.rs | 18 +++++++++++ .../sources/wrong_conversion_longfatarrow.rs | 7 ++++ .../wrong_conversion_longfatarrow.stderr | 11 +++++++ .../sources/wrong_conversion_longthinarrow.rs | 7 ++++ .../wrong_conversion_longthinarrow.stderr | 11 +++++++ .../sources/wrong_conversion_tildearrow.rs | 7 ++++ .../wrong_conversion_tildearrow.stderr | 11 +++++++ .../sources/wrong_conversion_trait_from.rs | 7 ++++ .../wrong_conversion_trait_from.stderr | 24 ++++++++++++++ .../sources/wrong_conversion_trait_fromstr.rs | 7 ++++ .../wrong_conversion_trait_fromstr.stderr | 28 ++++++++++++++++ .../sources/wrong_conversion_trait_tryfrom.rs | 7 ++++ .../wrong_conversion_trait_tryfrom.stderr | 26 +++++++++++++++ .../tests/sources/wrong_nonsense_1.rs | 7 ++++ .../tests/sources/wrong_nonsense_1.stderr | 5 +++ .../tests/sources/wrong_nonsense_2.rs | 7 ++++ .../tests/sources/wrong_nonsense_2.stderr | 5 +++ .../tests/sources/wrong_nonsense_3.rs | 7 ++++ .../tests/sources/wrong_nonsense_3.stderr | 5 +++ micronfig_macros/tests/sources/wrong_start.rs | 7 ++++ .../tests/sources/wrong_start.stderr | 11 +++++++ .../tests/sources/wrong_syntax_colon.rs | 7 ++++ .../tests/sources/wrong_syntax_colon.stderr | 11 +++++++ .../tests/sources/wrong_syntax_type.rs | 7 ++++ .../tests/sources/wrong_syntax_type.stderr | 11 +++++++ ...buf_use.rs => wrong_unqualified_import.rs} | 0 .../sources/wrong_unqualified_import.stderr | 9 ++++++ .../sources/wrong_unqualified_noimport.rs | 7 ++++ .../sources/wrong_unqualified_noimport.stderr | 19 +++++++++++ micronfig_macros/tests/tests.rs | 32 +++++++++++++++---- 38 files changed, 379 insertions(+), 22 deletions(-) create mode 100644 micronfig_macros/tests/sources/chain_single_down.rs create mode 100644 micronfig_macros/tests/sources/chain_single_up.rs create mode 100644 micronfig_macros/tests/sources/example_patchedporobot.rs create mode 100644 micronfig_macros/tests/sources/from_single_custom.rs create mode 100644 micronfig_macros/tests/sources/parse_single_custom.rs delete mode 100644 micronfig_macros/tests/sources/parse_single_ipaddr.rs rename micronfig_macros/tests/sources/{parse_single_pathbuf_full.rs => parse_single_pathbuf.rs} (100%) create mode 100644 micronfig_macros/tests/sources/tryfrom_single_custom.rs create mode 100644 micronfig_macros/tests/sources/wrong_conversion_longfatarrow.rs create mode 100644 micronfig_macros/tests/sources/wrong_conversion_longfatarrow.stderr create mode 100644 micronfig_macros/tests/sources/wrong_conversion_longthinarrow.rs create mode 100644 micronfig_macros/tests/sources/wrong_conversion_longthinarrow.stderr create mode 100644 micronfig_macros/tests/sources/wrong_conversion_tildearrow.rs create mode 100644 micronfig_macros/tests/sources/wrong_conversion_tildearrow.stderr create mode 100644 micronfig_macros/tests/sources/wrong_conversion_trait_from.rs create mode 100644 micronfig_macros/tests/sources/wrong_conversion_trait_from.stderr create mode 100644 micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.rs create mode 100644 micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.stderr create mode 100644 micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.rs create mode 100644 micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.stderr create mode 100644 micronfig_macros/tests/sources/wrong_nonsense_1.rs create mode 100644 micronfig_macros/tests/sources/wrong_nonsense_1.stderr create mode 100644 micronfig_macros/tests/sources/wrong_nonsense_2.rs create mode 100644 micronfig_macros/tests/sources/wrong_nonsense_2.stderr create mode 100644 micronfig_macros/tests/sources/wrong_nonsense_3.rs create mode 100644 micronfig_macros/tests/sources/wrong_nonsense_3.stderr create mode 100644 micronfig_macros/tests/sources/wrong_start.rs create mode 100644 micronfig_macros/tests/sources/wrong_start.stderr create mode 100644 micronfig_macros/tests/sources/wrong_syntax_colon.rs create mode 100644 micronfig_macros/tests/sources/wrong_syntax_colon.stderr create mode 100644 micronfig_macros/tests/sources/wrong_syntax_type.rs create mode 100644 micronfig_macros/tests/sources/wrong_syntax_type.stderr rename micronfig_macros/tests/sources/{parse_single_pathbuf_use.rs => wrong_unqualified_import.rs} (100%) create mode 100644 micronfig_macros/tests/sources/wrong_unqualified_import.stderr create mode 100644 micronfig_macros/tests/sources/wrong_unqualified_noimport.rs create mode 100644 micronfig_macros/tests/sources/wrong_unqualified_noimport.stderr diff --git a/micronfig_macros/src/lib.rs b/micronfig_macros/src/lib.rs index 430d534..695116c 100644 --- a/micronfig_macros/src/lib.rs +++ b/micronfig_macros/src/lib.rs @@ -1,6 +1,6 @@ extern crate proc_macro; use proc_macro::TokenStream; -use quote::quote; +use quote::{quote, ToTokens}; use syn::parse::{Parse, ParseStream}; use syn::{Ident, parse_macro_input, Token, Type}; use syn::punctuated::Punctuated; @@ -34,7 +34,10 @@ impl Parse for ConfigItem { if input.lookahead1().peek(Token![:]) { input.parse::()?; - input.parse::()?; + let string_type = input.parse::()?; + if string_type.to_token_stream().to_string() != "String" { + return Err(syn::Error::new_spanned(string_type, "first type of a conversion chain should always be `String`")) + } let mut types = vec![]; while let Ok(typ) = input.parse::() { @@ -47,7 +50,6 @@ impl Parse for ConfigItem { let types = vec![]; Ok(Self { identifier, types }) } - } } @@ -72,7 +74,7 @@ impl Parse for Conversion { Ok(Conversion::FromStr) } else { - Err(input.error("Cannot determine conversion method to use; valid conversion tokens are `->` (From), `=>` (TryFrom) and `>` (FromStr).")) + Err(input.error("cannot determine conversion method to use; valid conversion tokens are `->` (From), `=>` (TryFrom) and `>` (FromStr).")) } } } @@ -84,12 +86,12 @@ pub fn config(input: TokenStream) -> TokenStream { let cache_code = quote! { #[allow(non_snake_case)] mod _cache { - pub static lock: std::sync::OnceLock = std::sync::OnceLock::new(); + pub static _lock: std::sync::OnceLock = std::sync::OnceLock::new(); } #[allow(non_snake_case)] fn _cache() -> &'static micronfig::cache::Cache { - _cache::lock.get_or_init(micronfig::cache::Cache::new) + _cache::_lock.get_or_init(micronfig::cache::Cache::new) } }; @@ -135,12 +137,12 @@ pub fn config(input: TokenStream) -> TokenStream { quote! { #[allow(non_snake_case)] mod #identifier { - pub(super) static lock: std::sync::OnceLock> = std::sync::OnceLock::new(); + pub(super) static _lock: std::sync::OnceLock> = std::sync::OnceLock::new(); } #[allow(non_snake_case)] pub(crate) fn #identifier() -> &'static Option<#last_type> { - #identifier::lock.get_or_init(|| { + #identifier::_lock.get_or_init(|| { let key: std::ffi::OsString = #identifier_string.into(); let value: Option = _cache().get(&key); diff --git a/micronfig_macros/tests/sources/chain_single_down.rs b/micronfig_macros/tests/sources/chain_single_down.rs new file mode 100644 index 0000000..b75eaeb --- /dev/null +++ b/micronfig_macros/tests/sources/chain_single_down.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String > u128 => u64 => u32 => u16 => u8, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/chain_single_up.rs b/micronfig_macros/tests/sources/chain_single_up.rs new file mode 100644 index 0000000..9557df0 --- /dev/null +++ b/micronfig_macros/tests/sources/chain_single_up.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String > u8 -> u16 -> u32 -> u64 -> u128, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/example_patchedporobot.rs b/micronfig_macros/tests/sources/example_patchedporobot.rs new file mode 100644 index 0000000..e69de29 diff --git a/micronfig_macros/tests/sources/from_single_custom.rs b/micronfig_macros/tests/sources/from_single_custom.rs new file mode 100644 index 0000000..f845c09 --- /dev/null +++ b/micronfig_macros/tests/sources/from_single_custom.rs @@ -0,0 +1,16 @@ +#[derive(std::fmt::Debug)] +struct MyCustomStruct(String); + +impl From for MyCustomStruct { + fn from(value: String) -> Self { + Self(value) + } +} + +micronfig::config! { + GARASAUTO: String -> crate::MyCustomStruct, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/parse_single_custom.rs b/micronfig_macros/tests/sources/parse_single_custom.rs new file mode 100644 index 0000000..dd0918e --- /dev/null +++ b/micronfig_macros/tests/sources/parse_single_custom.rs @@ -0,0 +1,18 @@ +#[derive(std::fmt::Debug)] +struct MyCustomStruct(String); + +impl std::str::FromStr for MyCustomStruct { + type Err = (); + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_owned())) + } +} + +micronfig::config! { + GARASAUTO: String > crate::MyCustomStruct, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/parse_single_ipaddr.rs b/micronfig_macros/tests/sources/parse_single_ipaddr.rs deleted file mode 100644 index 300c8c8..0000000 --- a/micronfig_macros/tests/sources/parse_single_ipaddr.rs +++ /dev/null @@ -1,7 +0,0 @@ -micronfig::config! { - MY_IP_ADDR: String > IpAddr, -} - -fn main() { - println!("{:?}", MY_IP_ADDR()) -} diff --git a/micronfig_macros/tests/sources/parse_single_pathbuf_full.rs b/micronfig_macros/tests/sources/parse_single_pathbuf.rs similarity index 100% rename from micronfig_macros/tests/sources/parse_single_pathbuf_full.rs rename to micronfig_macros/tests/sources/parse_single_pathbuf.rs diff --git a/micronfig_macros/tests/sources/tryfrom_single_custom.rs b/micronfig_macros/tests/sources/tryfrom_single_custom.rs new file mode 100644 index 0000000..25c6df6 --- /dev/null +++ b/micronfig_macros/tests/sources/tryfrom_single_custom.rs @@ -0,0 +1,18 @@ +#[derive(std::fmt::Debug)] +struct MyCustomStruct(String); + +impl std::convert::TryFrom for MyCustomStruct { + type Error = (); + + fn try_from(value: String) -> Result { + Ok(Self(value)) + } +} + +micronfig::config! { + GARASAUTO: String => crate::MyCustomStruct, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_conversion_longfatarrow.rs b/micronfig_macros/tests/sources/wrong_conversion_longfatarrow.rs new file mode 100644 index 0000000..e5d7740 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_longfatarrow.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String ==> u64, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_conversion_longfatarrow.stderr b/micronfig_macros/tests/sources/wrong_conversion_longfatarrow.stderr new file mode 100644 index 0000000..9ec5769 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_longfatarrow.stderr @@ -0,0 +1,11 @@ +error: expected `,` + --> tests/sources/wrong_conversion_longfatarrow.rs:2:20 + | +2 | GARASAUTO: String ==> u64, + | ^ + +error[E0425]: cannot find function, tuple struct or tuple variant `GARASAUTO` in this scope + --> tests/sources/wrong_conversion_longfatarrow.rs:6:19 + | +6 | println!("{:?}", GARASAUTO()) + | ^^^^^^^^^ not found in this scope diff --git a/micronfig_macros/tests/sources/wrong_conversion_longthinarrow.rs b/micronfig_macros/tests/sources/wrong_conversion_longthinarrow.rs new file mode 100644 index 0000000..a5246d0 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_longthinarrow.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String --> u64, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_conversion_longthinarrow.stderr b/micronfig_macros/tests/sources/wrong_conversion_longthinarrow.stderr new file mode 100644 index 0000000..234f14f --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_longthinarrow.stderr @@ -0,0 +1,11 @@ +error: expected `,` + --> tests/sources/wrong_conversion_longthinarrow.rs:2:20 + | +2 | GARASAUTO: String --> u64, + | ^ + +error[E0425]: cannot find function, tuple struct or tuple variant `GARASAUTO` in this scope + --> tests/sources/wrong_conversion_longthinarrow.rs:6:19 + | +6 | println!("{:?}", GARASAUTO()) + | ^^^^^^^^^ not found in this scope diff --git a/micronfig_macros/tests/sources/wrong_conversion_tildearrow.rs b/micronfig_macros/tests/sources/wrong_conversion_tildearrow.rs new file mode 100644 index 0000000..9cded06 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_tildearrow.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String ~> u64, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_conversion_tildearrow.stderr b/micronfig_macros/tests/sources/wrong_conversion_tildearrow.stderr new file mode 100644 index 0000000..c658001 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_tildearrow.stderr @@ -0,0 +1,11 @@ +error: expected `,` + --> tests/sources/wrong_conversion_tildearrow.rs:2:20 + | +2 | GARASAUTO: String ~> u64, + | ^ + +error[E0425]: cannot find function, tuple struct or tuple variant `GARASAUTO` in this scope + --> tests/sources/wrong_conversion_tildearrow.rs:6:19 + | +6 | println!("{:?}", GARASAUTO()) + | ^^^^^^^^^ not found in this scope diff --git a/micronfig_macros/tests/sources/wrong_conversion_trait_from.rs b/micronfig_macros/tests/sources/wrong_conversion_trait_from.rs new file mode 100644 index 0000000..b83e57e --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_trait_from.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String -> u64, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_conversion_trait_from.stderr b/micronfig_macros/tests/sources/wrong_conversion_trait_from.stderr new file mode 100644 index 0000000..d268237 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_trait_from.stderr @@ -0,0 +1,24 @@ +error[E0277]: the trait bound `u64: From` is not satisfied + --> tests/sources/wrong_conversion_trait_from.rs:1:1 + | +1 | / micronfig::config! { +2 | | GARASAUTO: String -> u64, +3 | | } + | | ^ + | | | + | |_the trait `From` is not implemented for `u64` + | in this macro invocation + | + ::: src/lib.rs + | + | pub fn config(input: TokenStream) -> TokenStream { + | ------------------------------------------------ in this expansion of `micronfig::config!` + | + = help: the following other types implement trait `From`: + > + > + > + > + > + > + = note: required for `String` to implement `Into` diff --git a/micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.rs b/micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.rs new file mode 100644 index 0000000..936f845 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String > std::convert::Infallible, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.stderr b/micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.stderr new file mode 100644 index 0000000..68895db --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_trait_fromstr.stderr @@ -0,0 +1,28 @@ +error[E0277]: the trait bound `Infallible: FromStr` is not satisfied + --> tests/sources/wrong_conversion_trait_fromstr.rs:1:1 + | +1 | / micronfig::config! { +2 | | GARASAUTO: String > std::convert::Infallible, +3 | | } + | | ^ + | | | + | |_the trait `FromStr` is not implemented for `Infallible` + | in this macro invocation + | + ::: src/lib.rs + | + | pub fn config(input: TokenStream) -> TokenStream { + | ------------------------------------------------ in this expansion of `micronfig::config!` + | + = help: the following other types implement trait `FromStr`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `core::str::::parse` + --> $RUST/core/src/str/mod.rs diff --git a/micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.rs b/micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.rs new file mode 100644 index 0000000..b22f82d --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String => u64, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.stderr b/micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.stderr new file mode 100644 index 0000000..e8a556c --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_conversion_trait_tryfrom.stderr @@ -0,0 +1,26 @@ +error[E0277]: the trait bound `u64: From` is not satisfied + --> tests/sources/wrong_conversion_trait_tryfrom.rs:1:1 + | +1 | / micronfig::config! { +2 | | GARASAUTO: String => u64, +3 | | } + | | ^ + | | | + | |_the trait `From` is not implemented for `u64` + | in this macro invocation + | + ::: src/lib.rs + | + | pub fn config(input: TokenStream) -> TokenStream { + | ------------------------------------------------ in this expansion of `micronfig::config!` + | + = help: the following other types implement trait `From`: + > + > + > + > + > + > + = note: required for `String` to implement `Into` + = note: required for `u64` to implement `TryFrom` + = note: required for `String` to implement `TryInto` diff --git a/micronfig_macros/tests/sources/wrong_nonsense_1.rs b/micronfig_macros/tests/sources/wrong_nonsense_1.rs new file mode 100644 index 0000000..4f1a4b7 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_nonsense_1.rs @@ -0,0 +1,7 @@ +micronfig::config! { + garasauto!"68"3469l +} + +fn main() { + +} \ No newline at end of file diff --git a/micronfig_macros/tests/sources/wrong_nonsense_1.stderr b/micronfig_macros/tests/sources/wrong_nonsense_1.stderr new file mode 100644 index 0000000..46758fa --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_nonsense_1.stderr @@ -0,0 +1,5 @@ +error: expected `,` + --> tests/sources/wrong_nonsense_1.rs:2:11 + | +2 | garasauto!"68"3469l + | ^ diff --git a/micronfig_macros/tests/sources/wrong_nonsense_2.rs b/micronfig_macros/tests/sources/wrong_nonsense_2.rs new file mode 100644 index 0000000..ce7211a --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_nonsense_2.rs @@ -0,0 +1,7 @@ +micronfig::config! { + : -> +} + +fn main() { + +} \ No newline at end of file diff --git a/micronfig_macros/tests/sources/wrong_nonsense_2.stderr b/micronfig_macros/tests/sources/wrong_nonsense_2.stderr new file mode 100644 index 0000000..fc175ac --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_nonsense_2.stderr @@ -0,0 +1,5 @@ +error: expected identifier + --> tests/sources/wrong_nonsense_2.rs:2:2 + | +2 | : -> + | ^ diff --git a/micronfig_macros/tests/sources/wrong_nonsense_3.rs b/micronfig_macros/tests/sources/wrong_nonsense_3.rs new file mode 100644 index 0000000..6fd094e --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_nonsense_3.rs @@ -0,0 +1,7 @@ +micronfig::config! { + ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +} + +fn main() { + +} \ No newline at end of file diff --git a/micronfig_macros/tests/sources/wrong_nonsense_3.stderr b/micronfig_macros/tests/sources/wrong_nonsense_3.stderr new file mode 100644 index 0000000..de0a379 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_nonsense_3.stderr @@ -0,0 +1,5 @@ +error: expected identifier + --> tests/sources/wrong_nonsense_3.rs:2:2 + | +2 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, + | ^ diff --git a/micronfig_macros/tests/sources/wrong_start.rs b/micronfig_macros/tests/sources/wrong_start.rs new file mode 100644 index 0000000..629464b --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_start.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: i64, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_start.stderr b/micronfig_macros/tests/sources/wrong_start.stderr new file mode 100644 index 0000000..aa33cba --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_start.stderr @@ -0,0 +1,11 @@ +error: first type of a conversion chain should always be `String` + --> tests/sources/wrong_start.rs:2:13 + | +2 | GARASAUTO: i64, + | ^^^ + +error[E0425]: cannot find function, tuple struct or tuple variant `GARASAUTO` in this scope + --> tests/sources/wrong_start.rs:6:19 + | +6 | println!("{:?}", GARASAUTO()) + | ^^^^^^^^^ not found in this scope diff --git a/micronfig_macros/tests/sources/wrong_syntax_colon.rs b/micronfig_macros/tests/sources/wrong_syntax_colon.rs new file mode 100644 index 0000000..d18e54e --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_syntax_colon.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: , +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_syntax_colon.stderr b/micronfig_macros/tests/sources/wrong_syntax_colon.stderr new file mode 100644 index 0000000..be7b126 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_syntax_colon.stderr @@ -0,0 +1,11 @@ +error: expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, `dyn`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime + --> tests/sources/wrong_syntax_colon.rs:2:13 + | +2 | GARASAUTO: , + | ^ + +error[E0425]: cannot find function, tuple struct or tuple variant `GARASAUTO` in this scope + --> tests/sources/wrong_syntax_colon.rs:6:19 + | +6 | println!("{:?}", GARASAUTO()) + | ^^^^^^^^^ not found in this scope diff --git a/micronfig_macros/tests/sources/wrong_syntax_type.rs b/micronfig_macros/tests/sources/wrong_syntax_type.rs new file mode 100644 index 0000000..d4e7357 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_syntax_type.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO String, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_syntax_type.stderr b/micronfig_macros/tests/sources/wrong_syntax_type.stderr new file mode 100644 index 0000000..4b44edd --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_syntax_type.stderr @@ -0,0 +1,11 @@ +error: expected `,` + --> tests/sources/wrong_syntax_type.rs:2:12 + | +2 | GARASAUTO String, + | ^^^^^^ + +error[E0425]: cannot find function, tuple struct or tuple variant `GARASAUTO` in this scope + --> tests/sources/wrong_syntax_type.rs:6:19 + | +6 | println!("{:?}", GARASAUTO()) + | ^^^^^^^^^ not found in this scope diff --git a/micronfig_macros/tests/sources/parse_single_pathbuf_use.rs b/micronfig_macros/tests/sources/wrong_unqualified_import.rs similarity index 100% rename from micronfig_macros/tests/sources/parse_single_pathbuf_use.rs rename to micronfig_macros/tests/sources/wrong_unqualified_import.rs diff --git a/micronfig_macros/tests/sources/wrong_unqualified_import.stderr b/micronfig_macros/tests/sources/wrong_unqualified_import.stderr new file mode 100644 index 0000000..c2fc7a0 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_unqualified_import.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `PathBuf` in this scope + --> tests/sources/wrong_unqualified_import.rs:4:22 + | +4 | GARASAUTO: String > PathBuf, + | ^^^^^^^ not found in this scope + | + = help: consider importing one of these items: + crate::PathBuf + std::path::PathBuf diff --git a/micronfig_macros/tests/sources/wrong_unqualified_noimport.rs b/micronfig_macros/tests/sources/wrong_unqualified_noimport.rs new file mode 100644 index 0000000..75c092d --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_unqualified_noimport.rs @@ -0,0 +1,7 @@ +micronfig::config! { + GARASAUTO: String > PathBuf, +} + +fn main() { + println!("{:?}", GARASAUTO()) +} diff --git a/micronfig_macros/tests/sources/wrong_unqualified_noimport.stderr b/micronfig_macros/tests/sources/wrong_unqualified_noimport.stderr new file mode 100644 index 0000000..5ea88f1 --- /dev/null +++ b/micronfig_macros/tests/sources/wrong_unqualified_noimport.stderr @@ -0,0 +1,19 @@ +error[E0412]: cannot find type `PathBuf` in this scope + --> tests/sources/wrong_unqualified_noimport.rs:2:22 + | +2 | GARASAUTO: String > PathBuf, + | ^^^^^^^ not found in this scope + | + = help: consider importing this struct: + std::path::PathBuf + +error[E0412]: cannot find type `PathBuf` in this scope + --> tests/sources/wrong_unqualified_noimport.rs:2:22 + | +2 | GARASAUTO: String > PathBuf, + | ^^^^^^^ not found in this scope + | +help: consider importing this struct + | +1 + use std::path::PathBuf; + | diff --git a/micronfig_macros/tests/tests.rs b/micronfig_macros/tests/tests.rs index d111ed9..b6708f4 100644 --- a/micronfig_macros/tests/tests.rs +++ b/micronfig_macros/tests/tests.rs @@ -16,14 +16,32 @@ macro_rules! fail { } } +pass!(chain_single_down); +pass!(chain_single_up); pass!(empty); -pass!(string_single_explicit); -pass!(string_single_implicit); +pass!(from_single_custom); +pass!(parse_single_custom); +pass!(parse_single_i64); +pass!(parse_single_pathbuf); +pass!(parse_single_u64); pass!(string_multi_explicit); pass!(string_multi_implicit); pass!(string_multi_mixed); -pass!(parse_single_u64); -pass!(parse_single_i64); -pass!(parse_single_ipaddr); -pass!(parse_single_pathbuf_full); -pass!(parse_single_pathbuf_use); +pass!(string_single_explicit); +pass!(string_single_implicit); +pass!(tryfrom_single_custom); + +fail!(wrong_conversion_longfatarrow); +fail!(wrong_conversion_longthinarrow); +fail!(wrong_conversion_tildearrow); +fail!(wrong_conversion_trait_from); +fail!(wrong_conversion_trait_fromstr); +fail!(wrong_conversion_trait_tryfrom); +fail!(wrong_nonsense_1); +fail!(wrong_nonsense_2); +fail!(wrong_nonsense_3); +fail!(wrong_start); +fail!(wrong_syntax_colon); +fail!(wrong_syntax_type); +fail!(wrong_unqualified_import); +fail!(wrong_unqualified_noimport);