Browse Source

Show warning when using a disabled feature

Benjamin Sago 4 years ago
parent
commit
4e7aaf659b

+ 2 - 2
Justfile

@@ -60,12 +60,12 @@ export DOG_DEBUG := ""
 
 # run extended tests
 @xtests *args:
-    specsheet xtests/{live,madns,options}/*.toml -shide {{args}} \
+    specsheet xtests/{options,live,madns}/*.toml -shide {{args}} \
         -O cmd.target.dog="${CARGO_TARGET_DIR:-../../target}/debug/dog"
 
 # run extended tests (in release mode)
 @xtests-release *args:
-    specsheet xtests/{live,madns,options}/*.toml {{args}} \
+    specsheet xtests/{options,live,madns}/*.toml {{args}} \
         -O cmd.target.dog="${CARGO_TARGET_DIR:-../../target}/release/dog"
 
 # run extended tests (omitting certain feature tests)

+ 1 - 1
dns-transport/src/https.rs

@@ -77,7 +77,7 @@ impl Transport for HttpsTransport {
 
     #[cfg(not(feature = "with_https"))]
     fn send(&self, request: &Request) -> Result<Response, Error> {
-        unimplemented!("HTTPS feature disabled")
+        unreachable!("HTTPS feature disabled")
     }
 }
 

+ 1 - 1
dns-transport/src/tls.rs

@@ -60,7 +60,7 @@ impl Transport for TlsTransport {
 
     #[cfg(not(feature = "with_tls"))]
     fn send(&self, request: &Request) -> Result<Response, Error> {
-        unimplemented!("TLS feature disabled")
+        unreachable!("TLS feature disabled")
     }
 }
 

+ 22 - 0
src/main.rs

@@ -55,6 +55,7 @@ fn main() {
     match Options::getopts(env::args_os().skip(1)) {
         OptionsResult::Ok(options) => {
             info!("Running with options -> {:#?}", options);
+            disabled_feature_check(&options);
             exit(run(options));
         }
 
@@ -152,6 +153,27 @@ fn run(Options { requests, format, measure_time }: Options) -> i32 {
 }
 
 
+/// Checks whether the options contain parameters that will cause dog to fail
+/// because the feature is disabled by exiting if so.
+#[allow(unused)]
+fn disabled_feature_check(options: &Options) {
+    use std::process::exit;
+    use crate::connect::TransportType;
+
+    #[cfg(not(feature = "with_tls"))]
+    if options.requests.inputs.transport_types.contains(&TransportType::TLS) {
+        eprintln!("dog: Cannot use '--tls': This version of dog has been compiled without TLS support");
+        exit(exits::OPTIONS_ERROR);
+    }
+
+    #[cfg(not(feature = "with_https"))]
+    if options.requests.inputs.transport_types.contains(&TransportType::HTTPS) {
+        eprintln!("dog: Cannot use '--https': This version of dog has been compiled without HTTPS support");
+        exit(exits::OPTIONS_ERROR);
+    }
+}
+
+
 /// The possible status numbers dog can exit with.
 mod exits {
 

+ 16 - 0
xtests/features/none.toml

@@ -9,3 +9,19 @@ stdout = { string = "[-idna, -tls, -https]" }
 stderr = { empty = true }
 status = 0
 tags = [ 'features' ]
+
+[[cmd]]
+name = "The ‘--tls’ option is not accepted when the feature is disabled"
+shell = "dog --tls a.b.c.d"
+stdout = { empty = true }
+stderr = { file = "outputs/disabled_tls.txt" }
+status = 3
+tags = [ 'features' ]
+
+[[cmd]]
+name = "The ‘--https option is not accepted when the feature is disabled"
+shell = "dog --https a.b.c.d @name.server"
+stdout = { empty = true }
+stderr = { file = "outputs/disabled_https.txt" }
+status = 3
+tags = [ 'features' ]

+ 1 - 0
xtests/features/outputs/disabled_https.txt

@@ -0,0 +1 @@
+dog: Cannot use '--https': This version of dog has been compiled without HTTPS support

+ 1 - 0
xtests/features/outputs/disabled_tls.txt

@@ -0,0 +1 @@
+dog: Cannot use '--tls': This version of dog has been compiled without TLS support