Skip to content

Commit

Permalink
fix: use a helper function to expose the scratch_dir instead of expos…
Browse files Browse the repository at this point in the history
…ing it directly
  • Loading branch information
amaanq committed Aug 8, 2023
1 parent 34fbcfd commit 0d291f9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::helpers::fixtures::SCRATCH_DIR;
use crate::tests::helpers::fixtures::scratch_dir;

use std::path::Path;
use tree_sitter_loader::Loader;

Expand Down Expand Up @@ -27,6 +28,7 @@ fn detect_language_by_first_line_regex() {
)
.unwrap();
std::fs::create_dir(temp_dir.path().join("src")).unwrap();
std::fs::create_dir(temp_dir.path().join("src/tree_sitter")).unwrap();
std::fs::write(
temp_dir.path().join("src/grammar.json"),
r#"{"name":"strace"}"#,
Expand All @@ -39,8 +41,13 @@ fn detect_language_by_first_line_regex() {
extern const TSLanguage *tree_sitter_strace(void) {}"##,
)
.unwrap();
std::fs::write(
temp_dir.path().join("src/tree_sitter/parser.h"),
include_str!("../../../lib/include/tree_sitter/parser.h"),
)
.unwrap();

let mut loader = Loader::with_parser_lib_path(SCRATCH_DIR.clone());
let mut loader = Loader::with_parser_lib_path(scratch_dir().to_path_buf());
let config = loader
.find_language_configurations_at_path(temp_dir.path())
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tests/helpers/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ lazy_static! {
static ref FIXTURES_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures");
static ref HEADER_DIR: PathBuf = ROOT_DIR.join("lib").join("include");
static ref GRAMMARS_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures").join("grammars");
pub static ref SCRATCH_DIR: PathBuf = {
static ref SCRATCH_DIR: PathBuf = {
// https://doc.rust-lang.org/reference/conditional-compilation.html
let vendor = if cfg!(target_vendor = "apple") {
"apple"
Expand Down
4 changes: 4 additions & 0 deletions cli/src/tests/helpers/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub fn fixtures_dir<'a>() -> &'static Path {
&FIXTURES_DIR
}

pub fn scratch_dir<'a>() -> &'static Path {
&SCRATCH_DIR
}

pub fn get_language(name: &str) -> Language {
TEST_LOADER
.load_language_at_path(&GRAMMARS_DIR.join(name).join("src"), &HEADER_DIR)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod async_context_test;
mod corpus_test;
mod detect_langauge;
mod detect_language;
mod github_issue_test;
mod helpers;
mod highlight_test;
Expand Down

0 comments on commit 0d291f9

Please sign in to comment.