From 72e95d62a1dc23c9a567e77be13b3f7076b8b632 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Wed, 12 May 2021 16:49:58 +0200 Subject: [PATCH] added test for basic functions --- Cargo.toml | 3 +++ src/lib.rs | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 577c900..e4ada6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,6 @@ homepape = "https://github.com/Nirusu99/ytd-rs" repository = "https://github.com/Nirusu99/ytd-rs" readme = "README.md" + +[dependencies] +regex = "1" diff --git a/src/lib.rs b/src/lib.rs index ac9f607..01413cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,8 +2,27 @@ pub mod ytd; #[cfg(test)] mod tests { + use regex::Regex; + use std::env; + #[test] - fn it_works() { - assert_eq!(2 + 2, 4); + fn version() { + let ytd = crate::ytd::YoutubeDL::new( + env::current_dir() + .expect("couldn't get working directory") + .to_str() + .unwrap(), + // get youtube-dl version + vec![crate::ytd::Arg::new("--version")], + String::new(), + ) + .expect("Couldn't create youtube-dl"); + + let regex = Regex::new(r"\d{4}\.\d{2}\.\d{2}").unwrap(); + let output = ytd.download(); + + // check output + // fails if youtube-dl is not installed + assert!(regex.is_match(output.output())); } }