feat(cli): add test listing and allow users to parse a specific test number
This commit is contained in:
parent
33045ee898
commit
577d333849
2 changed files with 161 additions and 17 deletions
|
|
@ -195,6 +195,9 @@ struct Parse {
|
|||
pub open_log: bool,
|
||||
#[arg(long, help = "The path to an alternative config.json file")]
|
||||
pub config_path: Option<PathBuf>,
|
||||
#[arg(long, short = 'n', help = "Parse the contents of a specific test")]
|
||||
#[clap(conflicts_with = "paths", conflicts_with = "paths_file")]
|
||||
pub test_number: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
|
|
@ -410,6 +413,8 @@ fn run() -> Result<()> {
|
|||
let current_dir = env::current_dir().unwrap();
|
||||
let mut loader = loader::Loader::new()?;
|
||||
|
||||
let color = env::var("NO_COLOR").map_or(true, |v| v != "1");
|
||||
|
||||
match command {
|
||||
Commands::InitConfig(_) => {
|
||||
if let Ok(Some(config_path)) = Config::find_config_file() {
|
||||
|
|
@ -576,7 +581,22 @@ fn run() -> Result<()> {
|
|||
|
||||
let timeout = parse_options.timeout.unwrap_or_default();
|
||||
|
||||
let paths = collect_paths(parse_options.paths_file.as_deref(), parse_options.paths)?;
|
||||
let (paths, language) = if let Some(target_test) = parse_options.test_number {
|
||||
let (test_path, language_names) = test::get_tmp_test_file(target_test, color)?;
|
||||
let languages = loader.languages_at_path(¤t_dir)?;
|
||||
let language = languages
|
||||
.iter()
|
||||
.find(|(_, n)| language_names.contains(&Box::from(n.as_str())))
|
||||
.map(|(l, _)| l.clone());
|
||||
let paths =
|
||||
collect_paths(None, Some(vec![test_path.to_str().unwrap().to_owned()]))?;
|
||||
(paths, language)
|
||||
} else {
|
||||
(
|
||||
collect_paths(parse_options.paths_file.as_deref(), parse_options.paths)?,
|
||||
None,
|
||||
)
|
||||
};
|
||||
|
||||
let max_path_length = paths.iter().map(|p| p.chars().count()).max().unwrap_or(0);
|
||||
let mut has_error = false;
|
||||
|
|
@ -586,11 +606,14 @@ fn run() -> Result<()> {
|
|||
let should_track_stats = parse_options.stat;
|
||||
let mut stats = parse::Stats::default();
|
||||
|
||||
for path in paths {
|
||||
for path in &paths {
|
||||
let path = Path::new(&path);
|
||||
|
||||
let language =
|
||||
loader.select_language(path, ¤t_dir, parse_options.scope.as_deref())?;
|
||||
let language = if let Some(ref language) = language {
|
||||
language.clone()
|
||||
} else {
|
||||
loader.select_language(path, ¤t_dir, parse_options.scope.as_deref())?
|
||||
};
|
||||
parser
|
||||
.set_language(&language)
|
||||
.context("incompatible language")?;
|
||||
|
|
@ -645,8 +668,6 @@ fn run() -> Result<()> {
|
|||
env::set_var("TREE_SITTER_DEBUG", "1");
|
||||
}
|
||||
|
||||
let color = env::var("NO_COLOR").map_or(true, |v| v != "1");
|
||||
|
||||
loader.use_debug_build(test_options.debug_build);
|
||||
|
||||
let mut parser = Parser::new();
|
||||
|
|
@ -683,6 +704,7 @@ fn run() -> Result<()> {
|
|||
open_log: test_options.open_log,
|
||||
languages: languages.iter().map(|(l, n)| (n.as_str(), l)).collect(),
|
||||
color,
|
||||
test_num: 1,
|
||||
};
|
||||
|
||||
test::run_tests_at_path(&mut parser, &mut opts)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue