This commit is contained in:
JOLIMAITRE Matthieu 2022-09-20 03:08:36 +02:00
commit 8e2a03e3a7
11 changed files with 1045 additions and 0 deletions

29
src/test.rs Normal file
View file

@ -0,0 +1,29 @@
pub fn main(_capture: bool, _file: String, _test: Option<String>) {
let content = todo!();
let tests = find_tests(content);
for test in tests {
// compile
// run
}
}
pub fn find_tests(source: String) -> Vec<String> {
source
.split([' ', '(', ')', ';'])
.filter(|name| &name[0..5] == "test_")
.map(String::from)
.collect()
}
pub fn gen_test_main(test_file: &str, test: &str) -> String {
format!(
"
#include \"{test_file}\"
int main() {{
{test}();
return 0;
}}
"
)
}