Some tests

This commit is contained in:
southerntofu 2020-07-01 17:17:54 +02:00
parent d02aca6864
commit 603f040b97
13 changed files with 47 additions and 6 deletions

View File

@ -41,10 +41,10 @@ pub fn entry(basedir: &str, filter: impl Fn(&Path) -> bool, name: &str) -> Optio
}
Some(Entry::new(
path.clone(),
path.file_name().expect("Failed to read file name").to_os_string(),
basepath
))
path.clone(),
path.file_name().expect("Failed to read file name").to_os_string(),
basepath
))
}
/// Loads entire database from folder
@ -68,8 +68,8 @@ pub fn from(path_name: &str, filter: impl Fn(&Path) -> bool) -> Result<Vec<Entry
entry.clone(),
entry.file_name().expect("Failed to read file name").to_os_string(),
path.clone()
)
);
)
);
}
}
@ -142,3 +142,26 @@ pub fn is_executable(path: &Path) -> bool {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn can_load_db() {
let base_dir = "tests/success";
let entries = from(base_dir, is_executable).expect("Could not load db");
let entries_names: Vec<String> = entries.iter().map(|x| x.name.clone().into_string().unwrap()).collect();
let expected: Vec<String> = vec!("task", "symlink", "no_source").iter().map(|x| x.to_string()).collect();
assert_eq!(expected.len(), entries_names.len());
for entry in expected {
if !entries_names.contains(&entry.to_string()) {
panic!("Could not find {}", &entry);
}
}
}
}

3
tests/no_source Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
echo "LOL sourceless task"

1
tests/success/no_source Symbolic link
View File

@ -0,0 +1 @@
../no_source

1
tests/success/symlink Symbolic link
View File

@ -0,0 +1 @@
../symlink

View File

@ -0,0 +1 @@
../symlink.source

1
tests/success/task Symbolic link
View File

@ -0,0 +1 @@
../task

1
tests/success/task.source Symbolic link
View File

@ -0,0 +1 @@
../task.source

1
tests/symlink Symbolic link
View File

@ -0,0 +1 @@
task

1
tests/symlink.source Symbolic link
View File

@ -0,0 +1 @@
task.source

3
tests/task Executable file
View File

@ -0,0 +1,3 @@
#! /bin/bash
echo Hello

1
tests/task.source Normal file
View File

@ -0,0 +1 @@
https://tildegit.org/southerntofu/git-build.sh

3
tests/wrong_source Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
echo "Ce script ne devrait jamais être exécuté"

View File

@ -0,0 +1 @@
SDJSQKLDJQKLSDJQS