From e8dbe011d3d81c06a41342b6b5a66705e9c74ae2 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sat, 16 Mar 2024 20:12:43 -0400 Subject: [PATCH] test: fix header writes --- cli/src/tests/helpers/fixtures.rs | 40 +++++++++++-------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/cli/src/tests/helpers/fixtures.rs b/cli/src/tests/helpers/fixtures.rs index a3cecb63..6e473a61 100644 --- a/cli/src/tests/helpers/fixtures.rs +++ b/cli/src/tests/helpers/fixtures.rs @@ -7,6 +7,8 @@ use tree_sitter_highlight::HighlightConfiguration; use tree_sitter_loader::{CompileConfig, Loader}; use tree_sitter_tags::TagsConfiguration; +use crate::generate::ALLOC_HEADER; + include!("./dirs.rs"); lazy_static! { @@ -105,32 +107,18 @@ pub fn get_test_language(name: &str, parser_code: &str, path: Option<&Path>) -> let header_path = src_dir.join("tree_sitter"); fs::create_dir_all(&header_path).unwrap(); - fs::write(header_path.join("alloc.h"), tree_sitter::PARSER_HEADER) - .with_context(|| { - format!( - "Failed to write {:?}", - header_path.join("alloc.h").file_name().unwrap() - ) - }) - .unwrap(); - - fs::write(header_path.join("array.h"), tree_sitter::PARSER_HEADER) - .with_context(|| { - format!( - "Failed to write {:?}", - header_path.join("array.h").file_name().unwrap() - ) - }) - .unwrap(); - - fs::write(header_path.join("parser.h"), tree_sitter::PARSER_HEADER) - .with_context(|| { - format!( - "Failed to write {:?}", - header_path.join("parser.h").file_name().unwrap() - ) - }) - .unwrap(); + [ + ("alloc.h", ALLOC_HEADER), + ("array.h", tree_sitter::ARRAY_HEADER), + ("parser.h", tree_sitter::PARSER_HEADER), + ] + .iter() + .for_each(|(file, content)| { + let file = header_path.join(file); + fs::write(&file, content) + .with_context(|| format!("Failed to write {:?}", file.file_name().unwrap())) + .unwrap(); + }); let paths_to_check = if let Some(scanner_path) = &scanner_path { vec![parser_path, scanner_path.clone()]