Skip to content

Commit

Permalink
Merge #17
Browse files Browse the repository at this point in the history
17: Remove `#[cfg(not(test))]` feature gate on `xflags!` r=matklad a=lnicola

Closes #14

Co-authored-by: Laurențiu Nicola <[email protected]>
  • Loading branch information
bors[bot] and lnicola authored Mar 2, 2022
2 parents fd9ab26 + 8a04ae4 commit b3617e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xflags"
version = "0.2.3" # NB: update me in 3 places
version = "0.2.4" # NB: update me in 3 places
description = "Moderately simple command line arguments parser."
categories = ["command-line-interface"]
license = "MIT OR Apache-2.0"
Expand All @@ -14,4 +14,4 @@ exclude = [".github/", "bors.toml", "rustfmt.toml"]
members = ["xtask", "xflags-macros"]

[dependencies]
xflags-macros = { path = "./xflags-macros", version = "=0.2.3" }
xflags-macros = { path = "./xflags-macros", version = "=0.2.4" }
2 changes: 1 addition & 1 deletion xflags-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xflags-macros"
version = "0.2.3"
version = "0.2.4"
description = "Private implementation details of xflags."
license = "MIT OR Apache-2.0"
repository = "https://github.com/matklad/xflags"
Expand Down
15 changes: 10 additions & 5 deletions xflags-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ mod parse;
mod emit;
mod update;

#[cfg(not(test))]
#[proc_macro]
pub fn xflags(ts: proc_macro::TokenStream) -> proc_macro::TokenStream {
let cmd = parse::parse(ts).unwrap();
let text = emit::emit(&cmd);
text.parse().unwrap()
pub fn xflags(_ts: proc_macro::TokenStream) -> proc_macro::TokenStream {
// Stub out the code, but let rust-analyzer resolve the invocation
#[cfg(not(test))]
{
let cmd = parse::parse(_ts).unwrap();
let text = emit::emit(&cmd);
text.parse().unwrap()
}
#[cfg(test)]
unimplemented!()
}

#[cfg(test)]
Expand Down
8 changes: 8 additions & 0 deletions xflags-macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ pub(crate) struct Error {
msg: String,
}

impl std::error::Error for Error {}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.msg)
}
}

pub(crate) fn parse(ts: TokenStream) -> Result<ast::XFlags> {
let mut p = Parser::new(ts);
xflags(&mut p)
Expand Down

0 comments on commit b3617e4

Please sign in to comment.