Skip to content

Commit ed638d0

Browse files
Add test to ensure derives work without a direct serde dependency
1 parent 3cadfcc commit ed638d0

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ exclude = [".github"]
1919
name = "simple"
2020
required-features = ["toml"]
2121

22+
[[test]]
23+
name = "indirect-serde"
24+
path = "tests/indirect-serde/run.rs"
25+
harness = false
26+
2227

2328
[features]
2429
default = ["toml", "yaml", "json5"]

tests/indirect-serde/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

tests/indirect-serde/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "indirect-serde"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
confique = { path = "../..", default-features = false }

tests/indirect-serde/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is just a compile test to make sure `confique`'s derives also work when the using crate does not have `serde` in its direct dependencies.
2+
Having this test as separate folder with a `run.rs` calling `cargo` was the easiest way I found to do that.
3+
That way, this is also executed as part of `cargo test`.

tests/indirect-serde/run.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
let res = Command::new("cargo")
5+
.args(["check"])
6+
.current_dir("tests/indirect-serde")
7+
.status();
8+
9+
assert!(res.is_ok_and(|exitcode| exitcode.success()));
10+
}

tests/indirect-serde/src/main.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![allow(dead_code)]
2+
3+
use confique::Config;
4+
5+
#[derive(Config)]
6+
struct Conf {
7+
#[config(deserialize_with = my_deserialize_fn)]
8+
username: String,
9+
10+
normal: u32,
11+
12+
opt: Option<String>,
13+
14+
#[config(nested)]
15+
nested: Nested,
16+
}
17+
18+
#[derive(Config)]
19+
struct Nested {
20+
#[config(env = "APP_PORT")]
21+
port: u16,
22+
23+
#[config(default = "127.0.0.1")]
24+
bind: std::net::IpAddr,
25+
26+
#[config(default = ["x-user", "x-password"])]
27+
headers: Vec<String>,
28+
}
29+
30+
fn my_deserialize_fn<'de, D>(_: D) -> Result<String, D::Error>
31+
where
32+
D: confique::serde::Deserializer<'de>,
33+
{
34+
todo!()
35+
}
36+
37+
fn main() {}

0 commit comments

Comments
 (0)