summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-28 17:13:47 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-28 17:13:47 +0000
commit558e213ab496ccb7949dab36aeb60149d3137d99 (patch)
treea5f7bc77e05278d54ce3ae27af57d0da4fd708e4
parentee5b3c8166be03876286508babfacde6d0a6cf54 (diff)
downloadgentoo-utils-558e213ab496ccb7949dab36aeb60149d3137d99.tar.gz
add porthole tests to meson
-rw-r--r--meson.build1
-rw-r--r--tests/meson.build19
-rw-r--r--tests/porthole/meson.build5
-rw-r--r--tests/porthole/porthole.rs (renamed from tests/porthole.rs)20
-rw-r--r--tests/porthole/porthole.txt (renamed from testdata/porthole.txt)0
5 files changed, 34 insertions, 11 deletions
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
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
index 99abf89..99abf89 100644
--- a/testdata/porthole.txt
+++ b/tests/porthole/porthole.txt