Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test): add attributes for corpus tests #3060

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
335 changes: 164 additions & 171 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ strip = false
[workspace.dependencies]
ansi_term = "0.12.1"
anstyle = "1.0.6"
anyhow = "1.0.79"
anyhow = "1.0.80"
cc = "1.0.88"
clap = { version = "4.5.0", features = [
clap = { version = "4.5.1", features = [
"cargo",
"derive",
"env",
Expand All @@ -54,16 +54,16 @@ ctrlc = { version = "3.4.2", features = ["termination"] }
difference = "2.0.0"
dirs = "5.0.1"
filetime = "0.2.23"
fs4 = "0.7.0"
fs4 = "0.8.0"
git2 = "0.18.2"
glob = "0.3.1"
heck = "0.4.1"
html-escape = "0.2.13"
indexmap = "2.2.2"
indexmap = "2.2.4"
indoc = "2.0.4"
lazy_static = "1.4.0"
libloading = "0.8.1"
log = { version = "0.4.20", features = ["std"] }
log = { version = "0.4.21", features = ["std"] }
memchr = "2.7.1"
once_cell = "1.19.0"
path-slash = "0.2.1"
Expand All @@ -72,18 +72,18 @@ rand = "0.8.5"
regex = "1.10.3"
regex-syntax = "0.8.2"
rustc-hash = "1.1.0"
semver = "1.0.21"
serde = { version = "1.0.196", features = ["derive"] }
serde_derive = "1.0.196"
serde_json = { version = "1.0.113", features = ["preserve_order"] }
semver = "1.0.22"
serde = { version = "1.0.197", features = ["derive"] }
serde_derive = "1.0.197"
serde_json = { version = "1.0.114", features = ["preserve_order"] }
smallbitvec = "2.5.1"
tempfile = "3.10.1"
thiserror = "1.0.56"
thiserror = "1.0.57"
tiny_http = "0.12.0"
toml = "0.8.10"
unindent = "0.2.3"
walkdir = "2.4.0"
wasmparser = "0.200.0"
wasmparser = "0.201.0"
webbrowser = "0.8.12"
which = "6.0.0"

Expand Down
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
13 changes: 6 additions & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,16 @@ 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");

// Run the corpus tests. Look for them at two paths: `test/corpus` and `corpus`.
let mut test_corpus_dir = test_dir.join("corpus");
if !test_corpus_dir.is_dir() {
test_corpus_dir = current_dir.join("corpus");
}
// Run the corpus tests. Look for them in `test/corpus`.
let test_corpus_dir = test_dir.join("corpus");
if test_corpus_dir.is_dir() {
let mut opts = TestOptions {
path: test_corpus_dir,
Expand All @@ -578,6 +576,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
2 changes: 1 addition & 1 deletion cli/src/query_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn parse_position_comments(
let node = cursor.node();

// Find every comment node.
if node.kind().contains("comment") {
if node.kind().to_lowercase().contains("comment") {
if let Ok(text) = node.utf8_text(source) {
let mut position = node.start_position();
if position.row > 0 {
Expand Down