Pārlūkot izejas kodu

Fix some compilation errors with cfg feature attrs

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
Manos Pitsidianakis 7 mēneši atpakaļ
vecāks
revīzija
13e917d97b
2 mainītis faili ar 40 papildinājumiem un 33 dzēšanām
  1. 20 18
      meli/src/command/parser.rs
  2. 20 15
      meli/src/conf/tests.rs

+ 20 - 18
meli/src/command/parser.rs

@@ -1050,38 +1050,40 @@ pub fn manage_jobs(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>>
     Ok((input, Ok(Tab(ManageJobs))))
     Ok((input, Ok(Tab(ManageJobs))))
 }
 }
 
 
-#[cfg(feature = "cli-docs")]
 pub fn view_manpage(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
 pub fn view_manpage(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
     let mut check = arg_init! { min_arg:1, max_arg: 1, view_manpage };
     let mut check = arg_init! { min_arg:1, max_arg: 1, view_manpage };
     let (input, _) = tag("man")(input.trim())?;
     let (input, _) = tag("man")(input.trim())?;
     arg_chk!(start check, input);
     arg_chk!(start check, input);
     let (input, _) = is_a(" ")(input)?;
     let (input, _) = is_a(" ")(input)?;
     arg_chk!(inc check, input);
     arg_chk!(inc check, input);
+    #[allow(unused_variables)]
     let (input, manpage) = map_res(not_line_ending, std::str::from_utf8)(input.trim())?;
     let (input, manpage) = map_res(not_line_ending, std::str::from_utf8)(input.trim())?;
     let (input, _) = eof(input)?;
     let (input, _) = eof(input)?;
     arg_chk!(finish check, input);
     arg_chk!(finish check, input);
-    match crate::manpages::parse_manpage(manpage) {
-        Ok(m) => Ok((input, Ok(Tab(Man(m))))),
-        Err(err) => Ok((
+    #[cfg(feature = "cli-docs")]
+    {
+        match crate::manpages::parse_manpage(manpage) {
+            Ok(m) => Ok((input, Ok(Tab(Man(m))))),
+            Err(err) => Ok((
+                input,
+                Err(CommandError::BadValue {
+                    inner: err.to_string().into(),
+                    suggestions: Some(crate::manpages::POSSIBLE_VALUES),
+                }),
+            )),
+        }
+    }
+    #[cfg(not(feature = "cli-docs"))]
+    {
+        Ok((
             input,
             input,
-            Err(CommandError::BadValue {
-                inner: err.to_string().into(),
-                suggestions: Some(crate::manpages::POSSIBLE_VALUES),
+            Err(CommandError::Other {
+                inner: "this meli binary has not been compiled with the cli-docs feature".into(),
             }),
             }),
-        )),
+        ))
     }
     }
 }
 }
 
 
-#[cfg(not(feature = "cli-docs"))]
-pub fn view_manpage(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
-    Ok((
-        input,
-        Err(CommandError::Other {
-            inner: "this meli binary has not been compiled with the cli-docs feature".into(),
-        }),
-    ))
-}
-
 pub fn quit(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
 pub fn quit(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
     let mut check = arg_init! { min_arg:0, max_arg: 0, quit};
     let mut check = arg_init! { min_arg:0, max_arg: 0, quit};
     let (input, _) = tag("quit")(input.trim())?;
     let (input, _) = tag("quit")(input.trim())?;

+ 20 - 15
meli/src/conf/tests.rs

@@ -135,24 +135,29 @@ fn test_conf_config_parse() {
 
 
     /* Test sample config */
     /* Test sample config */
 
 
-    let example_config = FileSettings::EXAMPLE_CONFIG.replace("\n#", "\n");
-    let re = regex::Regex::new(r#"root_mailbox\s*=\s*"[^"]*""#).unwrap();
-    let example_config = re.replace_all(
-        &example_config,
-        &format!(r#"root_mailbox = "{}""#, tempdir.path().to_str().unwrap()),
-    );
+    // Sample config contains `crate::conf::composing::SendMail::Smtp` variant which only exists if
+    // meli is build with `smtp` feature.
+    if cfg!(feature = "smtp") {
+        let example_config = FileSettings::EXAMPLE_CONFIG.replace("\n#", "\n");
+        let re = regex::Regex::new(r#"root_mailbox\s*=\s*"[^"]*""#).unwrap();
+        let example_config = re.replace_all(
+            &example_config,
+            &format!(r#"root_mailbox = "{}""#, tempdir.path().to_str().unwrap()),
+        );
 
 
-    let new_file = ConfigFile::new(&example_config, &tempdir).unwrap();
-    let config = FileSettings::validate(new_file.path.clone(), true)
-        .expect("Could not parse example config!");
-    for (accname, acc) in config.accounts.iter() {
-        if !acc.extra.is_empty() {
-            panic!(
-                "In example config, account `{}` has unrecognised configuration entries: {:?}",
-                accname, acc.extra
-            );
+        let new_file = ConfigFile::new(&example_config, &tempdir).unwrap();
+        let config = FileSettings::validate(new_file.path.clone(), true)
+            .expect("Could not parse example config!");
+        for (accname, acc) in config.accounts.iter() {
+            if !acc.extra.is_empty() {
+                panic!(
+                    "In example config, account `{}` has unrecognised configuration entries: {:?}",
+                    accname, acc.extra
+                );
+            }
         }
         }
     }
     }
+
     if let Err(err) = tempdir.close() {
     if let Err(err) = tempdir.close() {
         eprintln!("Could not cleanup tempdir: {}", err);
         eprintln!("Could not cleanup tempdir: {}", err);
     }
     }