Skip to content

Commit

Permalink
feat(cli): switch skip-http for check-http flag
Browse files Browse the repository at this point in the history
CLOSES #42
  • Loading branch information
hobofan committed Mar 17, 2019
1 parent 4cdefd0 commit 6cec35c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Expand Up @@ -42,7 +42,7 @@ Usage:
Options:
-h --help Print this message
--dir Specify a directory to check (default is target/doc/<package>)
--skip-http Skip checking of 'http' and 'https' scheme links
--check-http Check 'http' and 'https' scheme links
--debug Use debug output
-v --verbose Use verbose output
-V --version Print version info and exit.
Expand All @@ -53,7 +53,7 @@ struct MainArgs {
arg_directory: Option<String>,
flag_verbose: bool,
flag_debug: bool,
flag_skip_http: bool,
flag_check_http: bool,
}

#[derive(Debug)]
Expand All @@ -64,7 +64,7 @@ pub struct CheckContext {
impl Into<CheckContext> for MainArgs {
fn into(self) -> CheckContext {
CheckContext {
check_http: !self.flag_skip_http,
check_http: self.flag_check_http,
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion tests/non_existent_http_link.rs
Expand Up @@ -26,12 +26,20 @@ mod non_existent_http_link {
.assert()
.success();

// fails with generated docs
// succeeds without --check-http flag
Command::cargo_bin("cargo-deadlinks")
.unwrap()
.arg("deadlinks")
.current_dir("./tests/non_existent_http_link")
.assert()
.success();

// fails with --check-http flag
Command::cargo_bin("cargo-deadlinks")
.unwrap()
.args(&["deadlinks", "--check-http"])
.current_dir("./tests/non_existent_http_link")
.assert()
.failure();
}
}
37 changes: 37 additions & 0 deletions tests/working_http_check.rs
@@ -0,0 +1,37 @@
extern crate assert_cmd;

use assert_cmd::prelude::*;
use std::process::Command;

mod working_http_check {
use super::*;

#[test]
fn works() {
match std::fs::remove_dir_all("./tests/working_http_check/target") {
Ok(_) => {}
Err(err) => match err.kind() {
std::io::ErrorKind::NotFound => {}
_ => panic!(
"Unexpected error when trying do remove target directory: {:?}",
err
),
},
};

// generate docs
Command::new("cargo")
.arg("doc")
.current_dir("./tests/working_http_check")
.assert()
.success();

// succeeds with --check-http flag
Command::cargo_bin("cargo-deadlinks")
.unwrap()
.args(&["deadlinks", "--check-http"])
.current_dir("./tests/working_http_check")
.assert()
.success();
}
}
1 change: 1 addition & 0 deletions tests/working_http_check/.gitignore
@@ -0,0 +1 @@
target
7 changes: 7 additions & 0 deletions tests/working_http_check/Cargo.toml
@@ -0,0 +1,7 @@
[package]
name = "simple_project"
version = "0.1.0"
authors = ["Maximilian Goisser <goisser94@gmail.com>"]
edition = "2018"

[dependencies]
15 changes: 15 additions & 0 deletions tests/working_http_check/src/lib.rs
@@ -0,0 +1,15 @@
/// Foo function
///
/// Has something to do with [some website](http://example.com).
pub fn foo() {}

/// Bar function
pub fn bar() {}

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}

0 comments on commit 6cec35c

Please sign in to comment.