"No tests found"
Closed this issue · 4 comments
tomhampshire commented
I'm getting a "No tests found" error. Tests run fine using vim-test, cargo test
and cargo nextest run
. See below for the example lib.rs
that fails to run:
use std::env;
use std::error::Error;
use std::fs;
pub struct Config {
pub filename: String,
pub query: String,
pub ignore_case: bool,
}
impl Config {
pub fn new(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("Not enough arguments");
}
let query = args[1].clone();
let filename = args[2].clone();
let ignore_case = env::var("IGNORE_CASE").is_ok();
Ok(Config {
filename,
query,
ignore_case,
})
}
}
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(config.filename)?;
for line in search(&config.query, &contents, config.ignore_case) {
println!("{}", line);
}
Ok(())
}
pub fn search<'a>(query: &str, contents: &'a str, case_insensitive: bool) -> Vec<&'a str> {
let query = if case_insensitive {
query.to_lowercase()
} else {
query.to_string()
};
let mut results = vec![];
if case_insensitive {
for line in contents.lines() {
if line.to_lowercase().contains(&query) {
results.push(line);
}
}
} else {
for line in contents.lines() {
if line.contains(&query) {
results.push(line);
}
}
}
results
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn case_sensitive_test() {
let query = "duct";
let contents = "\
Rust:
safe, fast, productive.
Duct tape.
Pick three.";
assert_eq!(
vec!["safe, fast, productive.",],
search(query, contents, false)
);
}
#[test]
fn case_insensitive_test() {
let query = "dUCt";
let contents = "\
Rust:
safe, fast, productive.
Duct tape.
Pick three.";
assert_eq!(
vec!["safe, fast, productive.", "Duct tape."],
search(query, contents, true)
);
}
}
rouge8 commented
Hmm, this file works for me. Do you have nvim-treesitter installed and the Rust grammar installed for that?
tomhampshire commented
I'm a numpty. This was exactly the problem...
I've just ported my nvim.init over to lua. That's my excuse, anyway...
tomhampshire commented
Thanks for your help.
tomhampshire commented
We should feed this info back to the neotest repo maintainer. It would be useful to have the information in the 'installation' section that the relevant treesitter languages must be installed...