Skip to content

Commit

Permalink
test: add basic build test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilerd committed Oct 12, 2020
1 parent c3fc72f commit bf0f75b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/command/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use structopt::StructOpt;

#[derive(StructOpt, Debug)]
pub struct AddOptions {
title: String,
pub title: String,
#[structopt(long)]
url: Option<String>,
pub url: Option<String>,
#[structopt(long, short)]
template: Option<String>,
pub template: Option<String>,
#[structopt(long)]
draw: bool,
pub draw: bool,
#[structopt(long)]
data: bool,
pub data: bool,
}

pub fn add(path: impl AsRef<Path>, options: AddOptions) -> Result<(), StapleError> {
Expand Down
39 changes: 39 additions & 0 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,42 @@ pub(crate) fn build(path: impl AsRef<Path>, develop: bool) -> Result<(), StapleE
StapleCommand::lock_file()?;
App::load(&path, develop)?.render()
}

#[cfg(test)]
mod test {
use crate::{
command::{
add::{add, AddOptions},
build::build,
},
test::setup,
};

#[test]
fn should_render_article_content() -> Result<(), Box<dyn std::error::Error>> {
let dir = setup();
crate::command::init::init(&dir)?;
let options = AddOptions {
title: "test-markdown".to_owned(),
url: None,
template: None,
draw: false,
data: false,
};
add(&dir, options)?;

let article = dir.join("data/test-markdown.md");
let string = std::fs::read_to_string(&article)?;
let string1 = format!("{}\n\n{}", string, "# hello");
std::fs::write(&article, string1)?;
build(&dir, false)?;

let x = "<h1>hello</h1>\n";
assert_eq!(
x,
std::fs::read_to_string(dir.join("public/test-markdown/index.html"))?
);

Ok(())
}
}
33 changes: 32 additions & 1 deletion src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ pub(crate) fn command(path: impl AsRef<Path>) -> Result<(), StapleError> {

#[cfg(test)]
mod test {
use crate::{command::list::command, test::setup};
use crate::{
command::{
add::{add, AddOptions},
list::command,
},
test::setup,
};

#[test]
fn test_list() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -34,4 +40,29 @@ mod test {

Ok(())
}

#[test]
fn should_show_article_list() -> Result<(), Box<dyn std::error::Error>> {
let dir = setup();
crate::command::init::init(&dir)?;
let options = AddOptions {
title: "test-one".to_owned(),
url: None,
template: None,
draw: true,
data: true,
};
add(&dir, options)?;

let options = AddOptions {
title: "test-two".to_owned(),
url: None,
template: None,
draw: false,
data: false,
};
add(&dir, options)?;

Ok(command(dir)?)
}
}

0 comments on commit bf0f75b

Please sign in to comment.