Description: detect if building in workspace and fence tests needing that
Author: Jonas Smedegaard <dr@jones.dk>
Bug: https://github.com/tokio-rs/axum/issues/2599
Last-Update: 2024-07-20
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- /dev/null
+++ b/axum-extra/build.rs
@@ -0,0 +1,13 @@
+use std::path::Path;
+
+fn main() {
+    let file_path = Path::new(
+        concat!(
+            env!("CARGO_MANIFEST_DIR"),
+            "/../axum/src/test_helpers/test_client.rs"
+        )
+    );
+    if file_path.exists() {
+        println!("cargo:rustc-cfg=feature=\"in-workspace\"");
+    }
+}
--- a/axum-extra/src/handler/or.rs
+++ b/axum-extra/src/handler/or.rs
@@ -104,6 +104,7 @@
     }
 }
 
+#[cfg(feature = "in-workspace")]
 #[cfg(test)]
 mod tests {
     use super::*;
--- a/axum-extra/src/routing/mod.rs
+++ b/axum-extra/src/routing/mod.rs
@@ -411,6 +411,7 @@
     impl<S> Sealed for axum::Router<S> {}
 }
 
+#[cfg(feature = "in-workspace")]
 #[cfg(test)]
 mod tests {
     use super::*;
--- a/axum-extra/Cargo.toml
+++ b/axum-extra/Cargo.toml
@@ -40,6 +40,7 @@
 tracing = ["axum-core/tracing", "axum/tracing", "dep:tracing"]
 typed-header = ["dep:headers"]
 typed-routing = ["dep:axum-macros", "dep:percent-encoding", "dep:serde_html_form", "dep:form_urlencoded"]
+in-workspace = []
 
 # Enabled by docs.rs because it uses all-features
 __private_docs = [
--- a/axum-extra/src/extract/form.rs
+++ b/axum-extra/src/extract/form.rs
@@ -97,7 +97,7 @@
     }
 }
 
-#[cfg(test)]
+#[cfg(all(test, feature = "in-workspace"))]
 mod tests {
     use super::*;
     use crate::test_helpers::*;
--- a/axum-extra/src/extract/query.rs
+++ b/axum-extra/src/extract/query.rs
@@ -202,7 +202,7 @@
     }
 }
 
-#[cfg(test)]
+#[cfg(all(test, feature = "in-workspace"))]
 mod tests {
     use super::*;
     use crate::test_helpers::*;
