Skip to content

Commit

Permalink
Merge pull request #12 from sapporo-wes/bug/9
Browse files Browse the repository at this point in the history
Fix issue #9
  • Loading branch information
fmaccha authored Jul 29, 2024
2 parents bee1910 + 3db43cd commit c8832c1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,20 @@ where

Ok(format!("{:x}", result))
}

// check for the existence of a cache_dir directory and create it if it does not exist
pub fn check_and_create_cache_dir() -> io::Result<()> {
let cache_dir_path = Path::new("tests/cache_dir");
if !cache_dir_path.exists() {
std::fs::create_dir_all(cache_dir_path)?;
}

Ok(())
}

// whether the current environment is M1 Mac
pub fn is_running_on_m1_mac() -> bool {
let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;
os == "macos" && arch == "aarch64"
}
30 changes: 29 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod common;
use std::fs;
use std::path::Path;

use common::{calculate_checksum, tataki};
use common::{calculate_checksum, check_and_create_cache_dir, is_running_on_m1_mac, tataki};

/*
test cases:
Expand Down Expand Up @@ -41,6 +41,8 @@ new test cases involving new features:
#[test]
// 1. default
fn output_in_csv() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(&["./inputs/toy.sam", "./inputs/toy.fa"], &[]);

let stdout = out.stdout;
Expand All @@ -65,6 +67,8 @@ fn output_in_csv() {
#[test]
// 2. -f yaml
fn output_in_yaml() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(&["./inputs/toy.sam", "./inputs/toy.fa"], &["-f", "yaml"]);

let stdout = out.stdout;
Expand All @@ -86,6 +90,8 @@ fn output_in_yaml() {
#[test]
// 3. -f json --cache-dir
fn output_in_json_and_can_keep_cache() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(
&[
"./inputs/toy.sam",
Expand Down Expand Up @@ -135,6 +141,8 @@ fn output_in_json_and_can_keep_cache() {
#[test]
// 4. -o file
fn can_output_to_file() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let _ = tataki(
&["./inputs/toy.sam", "./inputs/toy.fa"],
&["-o", "./cache_dir/output.csv"],
Expand All @@ -156,6 +164,8 @@ fn can_output_to_file() {
// 5. -c conf
// Check if the output becomes null when a conf without sam and fasta is specified.
fn can_use_config_file() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(
&["./inputs/toy.sam", "./inputs/toy.fa"],
&["-c", "./conf/module_order_test.conf"],
Expand Down Expand Up @@ -183,6 +193,8 @@ fn can_use_config_file() {
#[test]
// 6. --dry-run
fn can_dry_run() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(&["./inputs/toy.sam", "./inputs/toy.fa"], &["--dry-run"]);

let stdout = out.stdout;
Expand All @@ -204,6 +216,8 @@ fn can_dry_run() {
#[test]
// 7. --quiet
fn can_be_quiet() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(&["./inputs/toy.sam", "./inputs/toy.fa"], &["--quiet"]);

let stderr = out.stderr;
Expand All @@ -214,6 +228,8 @@ fn can_be_quiet() {
#[test]
// 8. --verbose
fn can_be_verbose() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(&["./inputs/toy.sam", "./inputs/toy.fa"], &["--verbose"]);

let stderr = out.stderr;
Expand All @@ -224,6 +240,14 @@ fn can_be_verbose() {
#[test]
// 9. -c cwl.conf
fn can_run_cwl() {
// TEMPORARY: skip this test on M1 Mac due (issue #9)
// This will be removed when tataki supports M1 Mac.
if is_running_on_m1_mac() {
return;
}

check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(
&["./inputs/toy.py", "./inputs/toy.fa"],
&["-c", "./conf/run_cwl_test.conf"],
Expand Down Expand Up @@ -252,6 +276,8 @@ fn can_run_cwl() {
// 10. --num-records <LINES>
// Check if tataki only reads a single records. The second line of the input file is in abnormal format. If tataki reads more than one record, this assert fails.
fn can_limit_the_number_of_output_records() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(&["./inputs/toy_invalid_flag.sam"], &["--num-records", "1"]);

let stdout = out.stdout;
Expand All @@ -277,6 +303,8 @@ fn can_limit_the_number_of_output_records() {
// 11. --tidy
// Check if tataki attempt to read the whole lines of the input file and fail when parsing the line right after `--num-records` lines.
fn can_read_entirety_of_input_file() {
check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(&["./inputs/toy.sam", "./inputs/toy.fa"], &["--tidy"]);

let stdout = out.stdout;
Expand Down

0 comments on commit c8832c1

Please sign in to comment.