Skip to content

Commit

Permalink
feat(test): add attributes for corpus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Feb 27, 2024
1 parent e75a362 commit 305efd3
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 61 deletions.
8 changes: 4 additions & 4 deletions cli/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ impl Loader {
Ok(())
}

pub fn languages_at_path(&mut self, path: &Path) -> Result<Vec<Language>> {
pub fn languages_at_path(&mut self, path: &Path) -> Result<Vec<(Language, String)>> {
if let Ok(configurations) = self.find_language_configurations_at_path(path, true) {
let mut language_ids = configurations
.iter()
.map(|c| c.language_id)
.map(|c| (c.language_id, c.language_name.clone()))
.collect::<Vec<_>>();
language_ids.sort_unstable();
language_ids.dedup();
language_ids
.into_iter()
.map(|id| self.language_for_id(id))
.map(|(id, name)| Ok((self.language_for_id(id)?, name)))
.collect::<Result<Vec<_>>>()
} else {
Ok(Vec::new())
Expand Down Expand Up @@ -1118,7 +1118,7 @@ impl Loader {
.first()
.cloned()
{
Ok(lang)
Ok(lang.0)
} else if let Some(lang) = self.language_configuration_for_first_line_regex(path)? {
Ok(lang.0)
} else {
Expand Down
6 changes: 4 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,10 @@ fn run() -> Result<()> {
}

let languages = loader.languages_at_path(&current_dir)?;
let language = languages
let language = &languages
.first()
.ok_or_else(|| anyhow!("No language found"))?;
.ok_or_else(|| anyhow!("No language found"))?
.0;
parser.set_language(language)?;

let test_dir = current_dir.join("test");
Expand All @@ -578,6 +579,7 @@ fn run() -> Result<()> {
exclude: test_options.exclude,
update: test_options.update,
open_log: test_options.open_log,
languages: languages.iter().map(|(l, n)| (n.as_str(), l)).collect(),
};

test::run_tests_at_path(&mut parser, &mut opts)?;
Expand Down

0 comments on commit 305efd3

Please sign in to comment.