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

@@ -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::{
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();

View File

@@ -0,0 +1,19 @@
+ something/package
+ something/package
- some#thing/package
+ =cat/package-1.0:0/2.0
- something/pac?kage
- =something/+package-1.0:3.0
- a b c
+ >=media-video/knob-goblin-1.0_alpha-r4
+ media-video/knobgoblin:4
- /hello
- group/-1.0
- >=/
- >=media-video/revised-knob-3.0aaaaaaaaa-r15
*** sanity check
> cat/test-2.0 cat/test-1.0
< cat/test-1.0 cat/test-2.0