add porthole tests to meson

This commit is contained in:
John Turner
2025-11-28 17:13:47 +00:00
parent ee5b3c8166
commit 558e213ab4
5 changed files with 34 additions and 11 deletions

View File

@@ -22,6 +22,7 @@ gentoo_utils = static_library(
if get_option('tests').enabled() if get_option('tests').enabled()
rust.test('unittests', gentoo_utils) rust.test('unittests', gentoo_utils)
subdir('tests')
endif endif
if get_option('fuzz').enabled() if get_option('fuzz').enabled()

View File

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

View File

@@ -0,0 +1,5 @@
tests += {
meson.current_source_dir() / 'porthole.rs': [
meson.current_source_dir() / 'porthole.txt',
],
}

View File

@@ -1,4 +1,4 @@
use std::cmp::Ordering; use std::{cmp::Ordering, env, fs};
use gentoo_utils::{ use gentoo_utils::{
Parseable, Parseable,
@@ -6,11 +6,6 @@ use gentoo_utils::{
}; };
use mon::{Parser, input::InputIter, tag}; use mon::{Parser, input::InputIter, tag};
static PORTHOLE_TXT: &'static str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/testdata/porthole.txt"
));
enum Operator { enum Operator {
Comment, Comment,
Yes, 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) comment.or(yes).or(no).or(eq).or(gt).or(lt)
} }
#[test] fn main() {
fn test_porthole() { let path = env::args()
for line in PORTHOLE_TXT.lines() { .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() { if line.is_empty() {
continue; continue;
} }
let operator = parse_operator() let operator = parse_operator()
.parse_finished(InputIter::new( .parse_finished(InputIter::new(
line.split_ascii_whitespace().nth(0).unwrap(), line.split_ascii_whitespace().next().unwrap(),
)) ))
.unwrap(); .unwrap();