Browse Source

Some tests

pull/1/head
southerntofu 1 year ago
parent
commit
603f040b97
  1. 35
      src/db.rs
  2. 3
      tests/no_source
  3. 1
      tests/success/no_source
  4. 1
      tests/success/symlink
  5. 1
      tests/success/symlink.source
  6. 1
      tests/success/task
  7. 1
      tests/success/task.source
  8. 1
      tests/symlink
  9. 1
      tests/symlink.source
  10. 3
      tests/task
  11. 1
      tests/task.source
  12. 3
      tests/wrong_source
  13. 1
      tests/wrong_source.source

35
src/db.rs

@ -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

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

1
tests/success/no_source

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

1
tests/success/symlink

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

1
tests/success/symlink.source

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

1
tests/success/task

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

1
tests/success/task.source

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

1
tests/symlink

@ -0,0 +1 @@
task

1
tests/symlink.source

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

3
tests/task

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

1
tests/task.source

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

3
tests/wrong_source

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

1
tests/wrong_source.source

@ -0,0 +1 @@
SDJSQKLDJQKLSDJQS
Loading…
Cancel
Save