Skip to content

Commit

Permalink
tests: Compile with no features
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 22, 2024
1 parent 31c7009 commit ac9fb01
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,9 @@ notify = "6.0"
temp-env = "0.3"
log = { version = "0.4", features = ["serde"] }

[[example]]
name = "async_source"
required-features = ["json", "async"]

[lints]
workspace = true
2 changes: 1 addition & 1 deletion examples/custom_file_format/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use config::{Config, File, FileStoredFormat, Format, Map, Value, ValueKind};
use std::io::{Error, ErrorKind};

/// The private and public key sources will be read into their associated variable:
#[derive(serde::Deserialize, Clone, Debug)]
#[derive(serde_derive::Deserialize, Clone, Debug)]
pub struct Settings {
pub private_key: Option<String>,
pub public_key: Option<String>,
Expand Down
6 changes: 6 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ use crate::{config::Config, path::Expression, source::Source, value::Value};
/// # use config::*;
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// # #[cfg(feature = "json")]
/// # {
/// let mut builder = Config::builder()
/// .set_default("default", "1")?
/// .add_source(File::new("config/settings", FileFormat::Json))
Expand All @@ -52,6 +54,7 @@ use crate::{config::Config, path::Expression, source::Source, value::Value};
/// // something went wrong
/// }
/// }
/// # }
/// # Ok(())
/// # }
/// ```
Expand All @@ -64,11 +67,14 @@ use crate::{config::Config, path::Expression, source::Source, value::Value};
/// # use std::error::Error;
/// # use config::*;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// # #[cfg(feature = "json")]
/// # {
/// let mut builder = Config::builder();
/// builder = builder.set_default("default", "1")?;
/// builder = builder.add_source(File::new("config/settings", FileFormat::Json));
/// builder = builder.add_source(File::new("config/settings.prod", FileFormat::Json));
/// builder = builder.set_override("override", "1")?;
/// # }
/// # Ok(())
/// # }
/// ```
Expand Down
3 changes: 3 additions & 0 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ impl ser::SerializeStructVariant for Unreachable {
mod test {
use super::*;
use serde::{Deserialize, Serialize};
#[cfg(not(feature = "json5"))]
use serde_derive::{Deserialize, Serialize};

#[test]
fn test_struct() {
Expand All @@ -699,6 +701,7 @@ mod test {
}

#[test]
#[cfg(feature = "json")]
fn test_nest() {
let val = serde_json::json! { {
"top": {
Expand Down
1 change: 1 addition & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ mod tests {
use crate::FileFormat;

#[test]
#[cfg(feature = "toml")]
fn test_i64() {
let c = Config::builder()
.add_source(File::new("tests/types/i64.toml", FileFormat::Toml))
Expand Down
4 changes: 4 additions & 0 deletions tests/async_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![cfg(feature = "async")]
#![cfg(feature = "json")]
#![cfg(feature = "toml")]

use async_trait::async_trait;
use config::{AsyncSource, Config, ConfigError, FileFormat, Format, Map, Value};
use std::{env, fs, path, str::FromStr};
Expand Down
1 change: 1 addition & 0 deletions tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ fn test_parse_string_and_list_ignore_list_parse_key_case() {
}

#[test]
#[cfg(feature = "convert-case")]
fn test_parse_nested_kebab() {
use config::Case;

Expand Down
4 changes: 4 additions & 0 deletions tests/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn test_file_required_not_found() {
}

#[test]
#[cfg(feature = "toml")]
fn test_file_auto() {
let c = Config::builder()
.add_source(File::with_name("tests/Settings-production"))
Expand All @@ -49,6 +50,7 @@ fn test_file_auto_not_found() {
}

#[test]
#[cfg(feature = "json")]
fn test_file_ext() {
let c = Config::builder()
.add_source(File::with_name("tests/Settings.json"))
Expand All @@ -58,7 +60,9 @@ fn test_file_ext() {
assert_eq!(c.get("debug").ok(), Some(true));
assert_eq!(c.get("production").ok(), Some(false));
}

#[test]
#[cfg(feature = "ini")]
fn test_file_second_ext() {
let c = Config::builder()
.add_source(File::with_name("tests/Settings2.default"))
Expand Down
2 changes: 2 additions & 0 deletions tests/integer_range.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "toml")]

use config::Config;

#[test]
Expand Down
2 changes: 2 additions & 0 deletions tests/legacy/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn test_file_required_not_found() {
}

#[test]
#[cfg(feature = "toml")]
fn test_file_auto() {
let mut c = Config::default();
c.merge(File::with_name("tests/Settings-production"))
Expand All @@ -45,6 +46,7 @@ fn test_file_auto_not_found() {
}

#[test]
#[cfg(feature = "json")]
fn test_file_ext() {
let mut c = Config::default();
c.merge(File::with_name("tests/Settings.json")).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions tests/log.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "json")]

#[macro_use]
extern crate serde_derive;

Expand Down Expand Up @@ -33,6 +35,7 @@ fn test_case_sensitivity_log_level_from_str() {
}

#[test]
#[cfg(feature = "json")]
fn test_case_sensitivity_json_from_str() {
// to confirm serde_json works as expected
let s = r#"{ "log": "error" }"#;
Expand Down
2 changes: 2 additions & 0 deletions tests/ron_enum.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "ron")]

use config::{Config, File, FileFormat};
use serde_derive::Deserialize;

Expand Down
4 changes: 2 additions & 2 deletions tests/unsigned_int.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![cfg(feature = "preserve_order")]

#[derive(serde::Deserialize, Eq, PartialEq, Debug)]
#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)]
struct Container<T> {
inner: T,
}

#[derive(serde::Deserialize, Eq, PartialEq, Debug)]
#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)]
struct Unsigned {
unsigned: u16,
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unsigned_int_hm.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![cfg(not(feature = "preserve_order"))]

#[derive(serde::Deserialize, Eq, PartialEq, Debug)]
#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)]
struct Container<T> {
inner: T,
}

#[derive(serde::Deserialize, Eq, PartialEq, Debug)]
#[derive(serde_derive::Deserialize, Eq, PartialEq, Debug)]
struct Unsigned {
unsigned: u16,
}
Expand Down
3 changes: 3 additions & 0 deletions tests/weird_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// Please don't be offended!
//

#![cfg(feature = "json")]
#![cfg(feature = "toml")]

use serde_derive::{Deserialize, Serialize};

use config::{File, FileFormat};
Expand Down

0 comments on commit ac9fb01

Please sign in to comment.