diff --git a/meson.build b/meson.build index 7bc2184..9e353d5 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ gentoo_utils = static_library( if get_option('tests').enabled() rust.test('unittests', gentoo_utils) + subdir('tests') endif if get_option('fuzz').enabled() diff --git a/tests/meson.build b/tests/meson.build index 69052cd..e99c9c7 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1 +1,18 @@ -subdir('fuzz') +tests = {} + +subdir('porthole') + +foreach test, test_args : tests + name = fs.name(test) + + test( + f'test_@name@', + executable( + f'test_@name@', + test, + dependencies: [mon, itertools], + link_with: [gentoo_utils], + ), + args: test_args, + ) +endforeach diff --git a/tests/porthole/meson.build b/tests/porthole/meson.build new file mode 100644 index 0000000..68f68fa --- /dev/null +++ b/tests/porthole/meson.build @@ -0,0 +1,5 @@ +tests += { + meson.current_source_dir() / 'porthole.rs': [ + meson.current_source_dir() / 'porthole.txt', + ], +} diff --git a/tests/porthole.rs b/tests/porthole/porthole.rs similarity index 87% rename from tests/porthole.rs rename to tests/porthole/porthole.rs index 3efbffe..4ff8d49 100644 --- a/tests/porthole.rs +++ b/tests/porthole/porthole.rs @@ -1,4 +1,4 @@ -use std::cmp::Ordering; +use std::{cmp::Ordering, env, fs}; use gentoo_utils::{ Parseable, @@ -6,11 +6,6 @@ use gentoo_utils::{ }; use mon::{Parser, input::InputIter, tag}; -static PORTHOLE_TXT: &'static str = include_str!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/testdata/porthole.txt" -)); - enum Operator { Comment, Yes, @@ -31,16 +26,21 @@ fn parse_operator<'a>() -> impl Parser<&'a str, Output = Operator> { comment.or(yes).or(no).or(eq).or(gt).or(lt) } -#[test] -fn test_porthole() { - for line in PORTHOLE_TXT.lines() { +fn main() { + let path = env::args() + .nth(1) + .expect("pass path to porthole.txt as first parameter"); + + let porthole_txt = fs::read_to_string(&path).expect("failed to open porthole.txt"); + + for line in porthole_txt.lines() { if line.is_empty() { continue; } let operator = parse_operator() .parse_finished(InputIter::new( - line.split_ascii_whitespace().nth(0).unwrap(), + line.split_ascii_whitespace().next().unwrap(), )) .unwrap(); diff --git a/testdata/porthole.txt b/tests/porthole/porthole.txt similarity index 100% rename from testdata/porthole.txt rename to tests/porthole/porthole.txt