Skip to content

Commit

Permalink
Merge pull request #32 from neuodev/ahmed/html5lib-tests-dir
Browse files Browse the repository at this point in the history
feat(parser): exit when html5lib-tests dir is missing
  • Loading branch information
jaytaph authored Oct 1, 2023
2 parents 0edd548 + 24cebc5 commit 2964b89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/target
target/
17 changes: 11 additions & 6 deletions src/bin/parser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use gosub_engine::html5_parser::parser::Html5Parser;
use regex::Regex;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::{env, fs, io};
use std::path::{Path, PathBuf};
use std::process::exit;
use std::{fs, io};

pub struct TestResults {
tests: usize, // Number of tests (as defined in the suite)
Expand All @@ -26,8 +27,12 @@ struct Test {
}

fn main() -> io::Result<()> {
let default_dir = "./html5lib-tests";
let dir = env::args().nth(1).unwrap_or(default_dir.to_string());
let default_dir = "tests/data/html5lib-tests".to_string();

if !Path::new(&default_dir).exists() {
println!("Missing 'html5lib-tests'. It is not located at '{default_dir}' \nIt should be cloned first from here https://github.com/html5lib/html5lib-tests");
exit(1)
}

let mut results = TestResults {
tests: 0,
Expand All @@ -37,7 +42,7 @@ fn main() -> io::Result<()> {
failed_position: 0,
};

for entry in fs::read_dir(dir + "/tree-construction")? {
for entry in fs::read_dir(default_dir + "/tree-construction")? {
let entry = entry?;
let path = entry.path();

Expand Down Expand Up @@ -144,7 +149,7 @@ fn read_tests(file_path: PathBuf) -> io::Result<Vec<Test>> {

fn run_tree_test(test_idx: usize, test: &Test, results: &mut TestResults) {
println!(
"🧪 Running test #{}: {}::{}",
"🧪 Running test #{}: {}:{}",
test_idx, test.file_path, test.line
);

Expand Down

0 comments on commit 2964b89

Please sign in to comment.