From 9b6eaae7c6795ee26698467767852c5def32d88f Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Sun, 15 Mar 2020 14:35:41 +0100 Subject: [PATCH] WIP --- .travis.yml | 2 +- clap_derive/src/derives/into_app.rs | 6 ++---- clap_derive/tests/macro-errors.rs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e3c826ca1f..002db85a204 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ jobs: - zlib1g-dev update: true before_script: - - cargo install cargo-tarpaulin + - cargo install cargo-tarpaulin --git https://github.com/xd009642/tarpaulin --branch develop script: - cargo tarpaulin --workspace --features "yaml unstable" --ciserver travis-ci --coveralls $TRAVIS_JOB_ID script: diff --git a/clap_derive/src/derives/into_app.rs b/clap_derive/src/derives/into_app.rs index da4c8c1afc9..842bff2d46f 100644 --- a/clap_derive/src/derives/into_app.rs +++ b/clap_derive/src/derives/into_app.rs @@ -12,8 +12,6 @@ // commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the // MIT/Apache 2.0 license. -use std::env; - use proc_macro2::TokenStream; use proc_macro_error::abort; use quote::{quote, quote_spanned}; @@ -56,7 +54,7 @@ pub fn gen_for_struct( } pub fn gen_for_enum(name: &syn::Ident) -> TokenStream { - let app_name = env::var("CARGO_PKG_NAME").ok().unwrap_or_default(); + let app_name = option_env!("CARGO_PKG_NAME").unwrap_or_default(); quote! { #[allow(dead_code, unreachable_code, unused_variables)] @@ -86,7 +84,7 @@ pub fn gen_for_enum(name: &syn::Ident) -> TokenStream { } fn gen_into_app_fn(attrs: &[syn::Attribute]) -> GenOutput { - let app_name = env::var("CARGO_PKG_NAME").ok().unwrap_or_default(); + let app_name = option_env!("CARGO_PKG_NAME").unwrap_or_default(); let attrs = Attrs::from_struct( proc_macro2::Span::call_site(), diff --git a/clap_derive/tests/macro-errors.rs b/clap_derive/tests/macro-errors.rs index 9c5bf43747b..17154153f8c 100644 --- a/clap_derive/tests/macro-errors.rs +++ b/clap_derive/tests/macro-errors.rs @@ -5,9 +5,21 @@ // , at your // option. This file may not be copied, modified, or distributed +use std::env; + #[rustversion::attr(any(not(stable), before(1.42)), ignore)] #[test] fn ui() { + let not_present = env::var("CARGO_PKG_NAME").is_err(); + + if not_present { + env::set_var("CARGO_PKG_NAME", "test"); + } + let t = trybuild::TestCases::new(); t.compile_fail("tests/ui/*.rs"); + + if not_present { + env::remove_var("CARGO_PKG_NAME"); + } }