Skip to content

Commit

Permalink
test(cli): integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdoret committed Oct 29, 2023
1 parent 34db9a9 commit dabf940
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 1 deletion.
167 changes: 167 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ edition = "2021"
[dependencies]
clap = { version = "4.4.2", features = ["derive"] }
sophia = { version = "0.8.0-alpha.3", features = ["xml"] }

[dev-dependencies]
assert_cmd = "2.0.12"
tempfile = "3.8.1"
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::str::FromStr;

// This lets clap automate validation of
// RDF formats from the command line
#[derive(Clone, Debug, ValueEnum)]
#[derive(Clone, Debug, PartialEq, ValueEnum)]
pub enum GraphFormat {
#[clap(alias = "ttl")]
Turtle,
Expand Down
43 changes: 43 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,46 @@ fn main() -> Result<(), Box<dyn Error>> {
RdfSerializer::serialize(output, output_format, parser.graph)?;
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
use assert_cmd::Command;
use std::fs::File;
use std::io::Write;
use tempfile::tempdir;

#[test]
fn test_format_from_path() {
assert_eq!(format_from_path("file.ttl"), Some(GraphFormat::Turtle));
assert_eq!(format_from_path("file.nt"), Some(GraphFormat::NTriples));
assert_eq!(format_from_path("file.rdf"), Some(GraphFormat::RdfXml));
assert_eq!(format_from_path("file.unknown"), None);
assert_eq!(format_from_path("file"), None);
}

#[test]
fn test_main() -> Result<(), Box<dyn Error>> {
let dir = tempdir()?;
let input_file = dir.path().join("input.ttl");

let mut input = File::create(&input_file)?;
writeln!(
input,
"<http://example.org> <http://example.org/predicate> \"object\" ."
)?;

let mut cmd = Command::cargo_bin("rdfpipe-rs").unwrap();
let status = cmd
.arg("-i")
.arg("turtle")
.arg("-o")
.arg("rdf-xml")
.arg(&input_file)
.assert();

status.success();

Ok(())
}
}

0 comments on commit dabf940

Please sign in to comment.