Skip to content

Commit

Permalink
Use examples in core preview test (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Jan 19, 2023
1 parent 44ce258 commit 7f321c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions tests/command_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ impl<const N: usize> ToArgs for [&str; N] {
}
}

impl ToArgs for Vec<String> {
fn to_args(&self) -> Vec<String> {
self.clone()
}
}

pub(crate) struct CommandBuilder {
args: Vec<String>,
expected_exit_code: i32,
Expand Down
30 changes: 25 additions & 5 deletions tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,28 @@ fn preview() {
.unwrap()
.port();

let builder =
CommandBuilder::new(format!("preview --http-port {port} foo.txt")).write("foo.txt", "foo");
let examples = fs::read_dir("examples")
.unwrap()
.map(|entry| {
entry
.unwrap()
.path()
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.into()
})
.collect::<Vec<String>>();

let mut args = vec![
"preview".to_string(),
"--http-port".to_string(),
port.to_string(),
];
args.extend(examples.clone());

let builder = CommandBuilder::new(args);

let _child = KillOnDrop(builder.command().spawn().unwrap());

Expand All @@ -41,11 +61,11 @@ fn preview() {
thread::sleep(Duration::from_millis(500));
}

assert!(
assert_regex_match!(
reqwest::blocking::get(format!("http://127.0.0.1:{port}/inscriptions"))
.unwrap()
.text()
.unwrap()
.contains("<a href=/inscription/")
.unwrap(),
format!(".*(<a href=/inscription/.*){{{}}}.*", examples.len())
);
}

0 comments on commit 7f321c4

Please sign in to comment.