2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
#[derive(Debug, PartialEq)]
|
2019-11-10 23:17:47 -08:00
|
|
|
pub(crate) struct Justfile<'src> {
|
2020-02-10 20:07:06 -08:00
|
|
|
pub(crate) recipes: Table<'src, Rc<Recipe<'src>>>,
|
2019-11-10 23:17:47 -08:00
|
|
|
pub(crate) assignments: Table<'src, Assignment<'src>>,
|
2020-02-10 20:07:06 -08:00
|
|
|
pub(crate) aliases: Table<'src, Alias<'src>>,
|
|
|
|
pub(crate) settings: Settings<'src>,
|
|
|
|
pub(crate) warnings: Vec<Warning<'src>>,
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2019-11-10 23:17:47 -08:00
|
|
|
impl<'src> Justfile<'src> {
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn first(&self) -> Option<&Recipe> {
|
2019-11-21 06:23:32 -08:00
|
|
|
let mut first: Option<&Recipe<Dependency>> = None;
|
2017-11-16 23:30:08 -08:00
|
|
|
for recipe in self.recipes.values() {
|
|
|
|
if let Some(first_recipe) = first {
|
2019-11-07 10:55:15 -08:00
|
|
|
if recipe.line_number() < first_recipe.line_number() {
|
2017-11-16 23:30:08 -08:00
|
|
|
first = Some(recipe)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
first = Some(recipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
first
|
|
|
|
}
|
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn count(&self) -> usize {
|
2017-11-16 23:30:08 -08:00
|
|
|
self.recipes.len()
|
|
|
|
}
|
|
|
|
|
2020-04-26 14:19:21 -07:00
|
|
|
pub(crate) fn suggest(&self, input: &str) -> Option<Suggestion> {
|
2018-08-27 16:03:52 -07:00
|
|
|
let mut suggestions = self
|
|
|
|
.recipes
|
|
|
|
.keys()
|
2020-04-26 14:19:21 -07:00
|
|
|
.map(|name| {
|
|
|
|
(edit_distance(name, input), Suggestion {
|
|
|
|
name,
|
|
|
|
target: None,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.chain(self.aliases.iter().map(|(name, alias)| {
|
|
|
|
(edit_distance(name, input), Suggestion {
|
|
|
|
name,
|
|
|
|
target: Some(alias.target.name.lexeme()),
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
.filter(|(distance, _suggestion)| distance < &3)
|
|
|
|
.collect::<Vec<(usize, Suggestion)>>();
|
|
|
|
suggestions.sort_by_key(|(distance, _suggestion)| *distance);
|
|
|
|
|
|
|
|
suggestions
|
|
|
|
.into_iter()
|
|
|
|
.map(|(_distance, suggestion)| suggestion)
|
|
|
|
.next()
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2019-12-25 06:12:06 -08:00
|
|
|
pub(crate) fn run<'run>(
|
|
|
|
&'run self,
|
|
|
|
config: &'run Config,
|
|
|
|
search: &'run Search,
|
|
|
|
overrides: &'run BTreeMap<String, String>,
|
|
|
|
arguments: &'run [String],
|
|
|
|
) -> RunResult<'run, ()> {
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
let argvec: Vec<&str> = if !arguments.is_empty() {
|
2020-01-15 02:16:13 -08:00
|
|
|
arguments.iter().map(String::as_str).collect()
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
} else if let Some(recipe) = self.first() {
|
|
|
|
let min_arguments = recipe.min_arguments();
|
|
|
|
if min_arguments > 0 {
|
|
|
|
return Err(RuntimeError::DefaultRecipeRequiresArguments {
|
|
|
|
recipe: recipe.name.lexeme(),
|
|
|
|
min_arguments,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
vec![recipe.name()]
|
|
|
|
} else {
|
|
|
|
return Err(RuntimeError::NoRecipes);
|
|
|
|
};
|
|
|
|
|
|
|
|
let arguments = argvec.as_slice();
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
let unknown_overrides = overrides
|
2018-08-27 16:03:52 -07:00
|
|
|
.keys()
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
.filter(|name| !self.assignments.contains_key(name.as_str()))
|
2020-01-15 02:16:13 -08:00
|
|
|
.map(String::as_str)
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
.collect::<Vec<&str>>();
|
2017-11-16 23:30:08 -08:00
|
|
|
|
|
|
|
if !unknown_overrides.is_empty() {
|
2018-08-27 16:03:52 -07:00
|
|
|
return Err(RuntimeError::UnknownOverrides {
|
|
|
|
overrides: unknown_overrides,
|
|
|
|
});
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2020-05-23 20:41:12 -07:00
|
|
|
let dotenv = if config.load_dotenv {
|
2020-07-19 05:01:46 -07:00
|
|
|
load_dotenv(&search.working_directory)?
|
2020-05-23 20:41:12 -07:00
|
|
|
} else {
|
|
|
|
BTreeMap::new()
|
|
|
|
};
|
2018-03-05 13:21:35 -08:00
|
|
|
|
2019-12-07 03:09:21 -08:00
|
|
|
let scope = {
|
|
|
|
let mut scope = Scope::new();
|
|
|
|
let mut unknown_overrides = Vec::new();
|
|
|
|
|
|
|
|
for (name, value) in overrides {
|
|
|
|
if let Some(assignment) = self.assignments.get(name) {
|
|
|
|
scope.bind(assignment.export, assignment.name, value.clone());
|
|
|
|
} else {
|
|
|
|
unknown_overrides.push(name.as_ref());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !unknown_overrides.is_empty() {
|
|
|
|
return Err(RuntimeError::UnknownOverrides {
|
|
|
|
overrides: unknown_overrides,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Evaluator::evaluate_assignments(
|
|
|
|
&self.assignments,
|
|
|
|
config,
|
|
|
|
&dotenv,
|
|
|
|
scope,
|
|
|
|
&self.settings,
|
2019-12-25 06:12:06 -08:00
|
|
|
search,
|
2019-12-07 03:09:21 -08:00
|
|
|
)?
|
|
|
|
};
|
2017-11-16 23:30:08 -08:00
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
if let Subcommand::Evaluate { .. } = config.subcommand {
|
2017-11-16 23:30:08 -08:00
|
|
|
let mut width = 0;
|
2019-12-07 03:09:21 -08:00
|
|
|
|
|
|
|
for name in scope.names() {
|
2017-11-16 23:30:08 -08:00
|
|
|
width = cmp::max(name.len(), width);
|
|
|
|
}
|
|
|
|
|
2019-12-07 03:09:21 -08:00
|
|
|
for binding in scope.bindings() {
|
|
|
|
println!(
|
|
|
|
"{0:1$} := \"{2}\"",
|
|
|
|
binding.name.lexeme(),
|
|
|
|
width,
|
|
|
|
binding.value
|
|
|
|
);
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut missing = vec![];
|
|
|
|
let mut grouped = vec![];
|
2018-08-27 16:03:52 -07:00
|
|
|
let mut rest = arguments;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
|
|
|
while let Some((argument, mut tail)) = rest.split_first() {
|
2019-05-15 12:43:47 -07:00
|
|
|
if let Some(recipe) = self.get_recipe(argument) {
|
2017-11-16 23:30:08 -08:00
|
|
|
if recipe.parameters.is_empty() {
|
2020-07-16 21:37:33 -07:00
|
|
|
grouped.push((recipe, &[][..]));
|
2017-11-16 23:30:08 -08:00
|
|
|
} else {
|
|
|
|
let argument_range = recipe.argument_range();
|
|
|
|
let argument_count = cmp::min(tail.len(), recipe.max_arguments());
|
2019-04-11 12:30:29 -07:00
|
|
|
if !argument_range.range_contains(&argument_count) {
|
2017-11-16 23:30:08 -08:00
|
|
|
return Err(RuntimeError::ArgumentCountMismatch {
|
2020-02-10 20:07:06 -08:00
|
|
|
recipe: recipe.name(),
|
2018-11-03 14:51:06 -07:00
|
|
|
parameters: recipe.parameters.iter().collect(),
|
2020-02-10 20:07:06 -08:00
|
|
|
found: tail.len(),
|
|
|
|
min: recipe.min_arguments(),
|
|
|
|
max: recipe.max_arguments(),
|
2017-11-16 23:30:08 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
grouped.push((recipe, &tail[0..argument_count]));
|
|
|
|
tail = &tail[argument_count..];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
missing.push(*argument);
|
|
|
|
}
|
|
|
|
rest = tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if !missing.is_empty() {
|
|
|
|
let suggestion = if missing.len() == 1 {
|
|
|
|
self.suggest(missing.first().unwrap())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2018-08-27 16:03:52 -07:00
|
|
|
return Err(RuntimeError::UnknownRecipes {
|
|
|
|
recipes: missing,
|
|
|
|
suggestion,
|
|
|
|
});
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
let context = RecipeContext {
|
2019-11-10 23:17:47 -08:00
|
|
|
settings: &self.settings,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
config,
|
|
|
|
scope,
|
2019-12-25 06:12:06 -08:00
|
|
|
search,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
};
|
2018-08-27 18:36:40 -07:00
|
|
|
|
2019-12-07 04:03:03 -08:00
|
|
|
let mut ran = BTreeSet::new();
|
2017-11-16 23:30:08 -08:00
|
|
|
for (recipe, arguments) in grouped {
|
2019-12-25 06:12:06 -08:00
|
|
|
self.run_recipe(&context, recipe, arguments, &dotenv, &search, &mut ran)?
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn get_alias(&self, name: &str) -> Option<&Alias> {
|
2019-08-23 20:45:57 -07:00
|
|
|
self.aliases.get(name)
|
|
|
|
}
|
|
|
|
|
2019-11-10 23:17:47 -08:00
|
|
|
pub(crate) fn get_recipe(&self, name: &str) -> Option<&Recipe<'src>> {
|
2019-05-15 12:43:47 -07:00
|
|
|
if let Some(recipe) = self.recipes.get(name) {
|
|
|
|
Some(recipe)
|
|
|
|
} else if let Some(alias) = self.aliases.get(name) {
|
2019-11-21 07:39:32 -08:00
|
|
|
Some(alias.target.as_ref())
|
2019-05-15 12:43:47 -07:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-07 03:09:21 -08:00
|
|
|
fn run_recipe<'run>(
|
2018-08-27 18:36:40 -07:00
|
|
|
&self,
|
2019-12-07 03:09:21 -08:00
|
|
|
context: &'run RecipeContext<'src, 'run>,
|
2019-11-10 23:17:47 -08:00
|
|
|
recipe: &Recipe<'src>,
|
2019-12-07 04:03:03 -08:00
|
|
|
arguments: &[&'run str],
|
2019-04-11 15:23:14 -07:00
|
|
|
dotenv: &BTreeMap<String, String>,
|
2019-12-25 06:12:06 -08:00
|
|
|
search: &'run Search,
|
2019-12-07 04:03:03 -08:00
|
|
|
ran: &mut BTreeSet<Vec<String>>,
|
2019-12-07 03:09:21 -08:00
|
|
|
) -> RunResult<'src, ()> {
|
2021-03-25 17:00:32 -07:00
|
|
|
let outer = Evaluator::evaluate_parameters(
|
2019-12-07 04:03:03 -08:00
|
|
|
context.config,
|
|
|
|
dotenv,
|
|
|
|
&recipe.parameters,
|
|
|
|
arguments,
|
|
|
|
&context.scope,
|
|
|
|
context.settings,
|
2019-12-25 06:12:06 -08:00
|
|
|
search,
|
2019-12-07 04:03:03 -08:00
|
|
|
)?;
|
|
|
|
|
2021-03-25 17:00:32 -07:00
|
|
|
let scope = outer.child();
|
|
|
|
|
2019-12-25 06:12:06 -08:00
|
|
|
let mut evaluator =
|
|
|
|
Evaluator::recipe_evaluator(context.config, dotenv, &scope, context.settings, search);
|
2019-12-07 04:03:03 -08:00
|
|
|
|
|
|
|
for Dependency { recipe, arguments } in &recipe.dependencies {
|
|
|
|
let mut invocation = vec![recipe.name().to_owned()];
|
|
|
|
|
|
|
|
for argument in arguments {
|
|
|
|
invocation.push(evaluator.evaluate_expression(argument)?);
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ran.contains(&invocation) {
|
|
|
|
let arguments = invocation
|
|
|
|
.iter()
|
|
|
|
.skip(1)
|
|
|
|
.map(String::as_ref)
|
|
|
|
.collect::<Vec<&str>>();
|
2019-12-25 06:12:06 -08:00
|
|
|
self.run_recipe(context, recipe, &arguments, dotenv, search, ran)?;
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|
2019-12-07 04:03:03 -08:00
|
|
|
|
2021-03-25 17:00:32 -07:00
|
|
|
recipe.run(context, dotenv, scope.child(), search)?;
|
2019-12-07 04:03:03 -08:00
|
|
|
|
2021-03-25 15:27:26 -07:00
|
|
|
let mut invocation = vec![recipe.name().to_owned()];
|
2019-12-07 04:03:03 -08:00
|
|
|
for argument in arguments.iter().cloned() {
|
|
|
|
invocation.push(argument.to_owned());
|
|
|
|
}
|
|
|
|
|
|
|
|
ran.insert(invocation);
|
2017-11-16 23:30:08 -08:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-08-21 15:13:54 -07:00
|
|
|
|
2020-09-17 19:43:04 -07:00
|
|
|
pub(crate) fn public_recipes(&self, source_order: bool) -> Vec<&Recipe<Dependency>> {
|
2020-08-21 15:13:54 -07:00
|
|
|
let mut recipes = self
|
|
|
|
.recipes
|
|
|
|
.values()
|
|
|
|
.map(AsRef::as_ref)
|
2020-09-17 19:43:04 -07:00
|
|
|
.filter(|recipe| recipe.public())
|
2020-08-21 15:13:54 -07:00
|
|
|
.collect::<Vec<&Recipe<Dependency>>>();
|
|
|
|
|
|
|
|
if source_order {
|
|
|
|
recipes.sort_by_key(|recipe| recipe.name.offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
recipes
|
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2019-11-10 23:17:47 -08:00
|
|
|
impl<'src> Display for Justfile<'src> {
|
2019-04-11 15:23:14 -07:00
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
2019-04-11 12:30:29 -07:00
|
|
|
let mut items = self.recipes.len() + self.assignments.len() + self.aliases.len();
|
2019-11-07 10:55:15 -08:00
|
|
|
for (name, assignment) in &self.assignments {
|
|
|
|
if assignment.export {
|
2017-11-16 23:30:08 -08:00
|
|
|
write!(f, "export ")?;
|
|
|
|
}
|
2019-12-07 03:09:21 -08:00
|
|
|
write!(f, "{} := {}", name, assignment.value)?;
|
2017-11-16 23:30:08 -08:00
|
|
|
items -= 1;
|
|
|
|
if items != 0 {
|
|
|
|
write!(f, "\n\n")?;
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 12:30:29 -07:00
|
|
|
for alias in self.aliases.values() {
|
2019-04-11 15:23:14 -07:00
|
|
|
write!(f, "{}", alias)?;
|
2019-04-11 12:30:29 -07:00
|
|
|
items -= 1;
|
|
|
|
if items != 0 {
|
|
|
|
write!(f, "\n\n")?;
|
|
|
|
}
|
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
for recipe in self.recipes.values() {
|
|
|
|
write!(f, "{}", recipe)?;
|
|
|
|
items -= 1;
|
|
|
|
if items != 0 {
|
|
|
|
write!(f, "\n\n")?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2019-11-07 10:55:15 -08:00
|
|
|
mod tests {
|
2017-11-16 23:30:08 -08:00
|
|
|
use super::*;
|
2019-04-11 15:23:14 -07:00
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
use testing::compile;
|
|
|
|
use RuntimeError::*;
|
|
|
|
|
|
|
|
run_error! {
|
|
|
|
name: unknown_recipes,
|
|
|
|
src: "a:\nb:\nc:",
|
|
|
|
args: ["a", "x", "y", "z"],
|
|
|
|
error: UnknownRecipes {
|
|
|
|
recipes,
|
|
|
|
suggestion,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipes, &["x", "y", "z"]);
|
|
|
|
assert_eq!(suggestion, None);
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-26 14:19:21 -07:00
|
|
|
run_error! {
|
|
|
|
name: unknown_recipes_show_alias_suggestion,
|
|
|
|
src: "
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
alias z := foo
|
|
|
|
",
|
|
|
|
args: ["zz"],
|
|
|
|
error: UnknownRecipes {
|
|
|
|
recipes,
|
|
|
|
suggestion,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipes, &["zz"]);
|
|
|
|
assert_eq!(suggestion, Some(Suggestion {
|
|
|
|
name: "z",
|
|
|
|
target: Some("foo"),
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
// This test exists to make sure that shebang recipes run correctly. Although
|
|
|
|
// this script is still executed by a shell its behavior depends on the value of
|
|
|
|
// a variable and continuing even though a command fails, whereas in plain
|
|
|
|
// recipes variables are not available in subsequent lines and execution stops
|
|
|
|
// when a line fails.
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: run_shebang,
|
|
|
|
src: "
|
|
|
|
a:
|
|
|
|
#!/usr/bin/env sh
|
|
|
|
code=200
|
|
|
|
x() { return $code; }
|
|
|
|
x
|
|
|
|
x
|
|
|
|
",
|
|
|
|
args: ["a"],
|
|
|
|
error: Code {
|
|
|
|
recipe,
|
|
|
|
line_number,
|
|
|
|
code,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert_eq!(line_number, None);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2017-11-17 17:28:06 -08:00
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: code_error,
|
|
|
|
src: "
|
|
|
|
fail:
|
|
|
|
@exit 100
|
|
|
|
",
|
|
|
|
args: ["fail"],
|
|
|
|
error: Code {
|
|
|
|
recipe,
|
|
|
|
line_number,
|
|
|
|
code,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipe, "fail");
|
|
|
|
assert_eq!(code, 100);
|
|
|
|
assert_eq!(line_number, Some(2));
|
2017-11-18 01:44:59 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: run_args,
|
|
|
|
src: r#"
|
|
|
|
a return code:
|
|
|
|
@x() { {{return}} {{code + "0"}}; }; x
|
|
|
|
"#,
|
|
|
|
args: ["a", "return", "15"],
|
|
|
|
error: Code {
|
|
|
|
recipe,
|
|
|
|
line_number,
|
|
|
|
code,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(code, 150);
|
|
|
|
assert_eq!(line_number, Some(2));
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: missing_some_arguments,
|
|
|
|
src: "a b c d:",
|
|
|
|
args: ["a", "b", "c"],
|
|
|
|
error: ArgumentCountMismatch {
|
|
|
|
recipe,
|
|
|
|
parameters,
|
|
|
|
found,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
let param_names = parameters
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.name.lexeme())
|
|
|
|
.collect::<Vec<&str>>();
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(param_names, ["b", "c", "d"]);
|
|
|
|
assert_eq!(found, 2);
|
|
|
|
assert_eq!(min, 3);
|
|
|
|
assert_eq!(max, 3);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: missing_some_arguments_variadic,
|
|
|
|
src: "a b c +d:",
|
|
|
|
args: ["a", "B", "C"],
|
|
|
|
error: ArgumentCountMismatch {
|
|
|
|
recipe,
|
|
|
|
parameters,
|
|
|
|
found,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
let param_names = parameters
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.name.lexeme())
|
|
|
|
.collect::<Vec<&str>>();
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(param_names, ["b", "c", "d"]);
|
|
|
|
assert_eq!(found, 2);
|
|
|
|
assert_eq!(min, 3);
|
|
|
|
assert_eq!(max, usize::MAX - 1);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: missing_all_arguments,
|
|
|
|
src: "a b c d:\n echo {{b}}{{c}}{{d}}",
|
|
|
|
args: ["a"],
|
|
|
|
error: ArgumentCountMismatch {
|
|
|
|
recipe,
|
|
|
|
parameters,
|
|
|
|
found,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
let param_names = parameters
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.name.lexeme())
|
|
|
|
.collect::<Vec<&str>>();
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(param_names, ["b", "c", "d"]);
|
|
|
|
assert_eq!(found, 0);
|
|
|
|
assert_eq!(min, 3);
|
|
|
|
assert_eq!(max, 3);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: missing_some_defaults,
|
|
|
|
src: "a b c d='hello':",
|
|
|
|
args: ["a", "b"],
|
|
|
|
error: ArgumentCountMismatch {
|
|
|
|
recipe,
|
|
|
|
parameters,
|
|
|
|
found,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
let param_names = parameters
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.name.lexeme())
|
|
|
|
.collect::<Vec<&str>>();
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(param_names, ["b", "c", "d"]);
|
|
|
|
assert_eq!(found, 1);
|
|
|
|
assert_eq!(min, 2);
|
|
|
|
assert_eq!(max, 3);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: missing_all_defaults,
|
|
|
|
src: "a b c='r' d='h':",
|
|
|
|
args: ["a"],
|
|
|
|
error: ArgumentCountMismatch {
|
|
|
|
recipe,
|
|
|
|
parameters,
|
|
|
|
found,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
let param_names = parameters
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.name.lexeme())
|
|
|
|
.collect::<Vec<&str>>();
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(param_names, ["b", "c", "d"]);
|
|
|
|
assert_eq!(found, 0);
|
|
|
|
assert_eq!(min, 1);
|
|
|
|
assert_eq!(max, 3);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: unknown_overrides,
|
|
|
|
src: "
|
|
|
|
a:
|
|
|
|
echo {{`f() { return 100; }; f`}}
|
|
|
|
",
|
|
|
|
args: ["foo=bar", "baz=bob", "a"],
|
|
|
|
error: UnknownOverrides { overrides },
|
|
|
|
check: {
|
|
|
|
assert_eq!(overrides, &["baz", "foo"]);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
run_error! {
|
|
|
|
name: export_failure,
|
|
|
|
src: r#"
|
|
|
|
export foo = "a"
|
|
|
|
baz = "c"
|
|
|
|
export bar = "b"
|
|
|
|
export abc = foo + bar + baz
|
|
|
|
|
|
|
|
wut:
|
|
|
|
echo $foo $bar $baz
|
|
|
|
"#,
|
|
|
|
args: ["--quiet", "wut"],
|
|
|
|
error: Code {
|
|
|
|
code: _,
|
|
|
|
line_number,
|
|
|
|
recipe,
|
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipe, "wut");
|
|
|
|
assert_eq!(line_number, Some(7));
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
macro_rules! test {
|
|
|
|
($name:ident, $input:expr, $expected:expr $(,)*) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
test($input, $expected);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test(input: &str, expected: &str) {
|
|
|
|
let justfile = compile(input);
|
|
|
|
let actual = format!("{:#}", justfile);
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
println!("Re-parsing...");
|
|
|
|
let reparsed = compile(&actual);
|
|
|
|
let redumped = format!("{:#}", reparsed);
|
|
|
|
assert_eq!(redumped, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_empty,
|
|
|
|
"
|
|
|
|
|
|
|
|
# hello
|
|
|
|
|
|
|
|
|
|
|
|
",
|
|
|
|
"",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_string_default,
|
|
|
|
r#"
|
|
|
|
|
|
|
|
foo a="b\t":
|
|
|
|
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"foo a="b\t":"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_multiple,
|
|
|
|
r#"
|
|
|
|
a:
|
|
|
|
b:
|
|
|
|
"#,
|
|
|
|
r#"a:
|
|
|
|
|
|
|
|
b:"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_variadic,
|
|
|
|
r#"
|
|
|
|
|
|
|
|
foo +a:
|
|
|
|
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"foo +a:"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_variadic_string_default,
|
|
|
|
r#"
|
|
|
|
|
|
|
|
foo +a="Hello":
|
|
|
|
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"foo +a="Hello":"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_raw_string_default,
|
|
|
|
r#"
|
|
|
|
|
|
|
|
foo a='b\t':
|
|
|
|
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"foo a='b\t':"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_export,
|
|
|
|
r#"
|
|
|
|
export a := "hello"
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"export a := "hello""#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_alias_after_target,
|
|
|
|
r#"
|
|
|
|
foo:
|
|
|
|
echo a
|
|
|
|
alias f := foo
|
|
|
|
"#,
|
|
|
|
r#"alias f := foo
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo a"#
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_alias_before_target,
|
|
|
|
r#"
|
|
|
|
alias f := foo
|
|
|
|
foo:
|
|
|
|
echo a
|
|
|
|
"#,
|
|
|
|
r#"alias f := foo
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo a"#
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_alias_with_comment,
|
|
|
|
r#"
|
|
|
|
alias f := foo #comment
|
|
|
|
foo:
|
|
|
|
echo a
|
|
|
|
"#,
|
|
|
|
r#"alias f := foo
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo a"#
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_complex,
|
|
|
|
"
|
|
|
|
x:
|
|
|
|
y:
|
|
|
|
z:
|
|
|
|
foo := \"xx\"
|
|
|
|
bar := foo
|
|
|
|
goodbye := \"y\"
|
|
|
|
hello a b c : x y z #hello
|
|
|
|
#! blah
|
|
|
|
#blarg
|
|
|
|
{{ foo + bar}}abc{{ goodbye\t + \"x\" }}xyz
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
",
|
|
|
|
"bar := foo
|
|
|
|
|
|
|
|
foo := \"xx\"
|
|
|
|
|
|
|
|
goodbye := \"y\"
|
|
|
|
|
|
|
|
hello a b c: x y z
|
|
|
|
#! blah
|
|
|
|
#blarg
|
|
|
|
{{foo + bar}}abc{{goodbye + \"x\"}}xyz
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
|
|
|
|
x:
|
|
|
|
|
|
|
|
y:
|
|
|
|
|
|
|
|
z:"
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_shebang,
|
|
|
|
"
|
|
|
|
practicum := 'hello'
|
|
|
|
install:
|
|
|
|
\t#!/bin/sh
|
|
|
|
\tif [[ -f {{practicum}} ]]; then
|
|
|
|
\t\treturn
|
|
|
|
\tfi
|
|
|
|
",
|
|
|
|
"practicum := 'hello'
|
|
|
|
|
|
|
|
install:
|
|
|
|
#!/bin/sh
|
|
|
|
if [[ -f {{practicum}} ]]; then
|
|
|
|
\treturn
|
|
|
|
fi",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_simple_shebang,
|
|
|
|
"a:\n #!\n print(1)",
|
|
|
|
"a:\n #!\n print(1)",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_assignments,
|
|
|
|
r#"a := "0"
|
|
|
|
c := a + b + a + b
|
|
|
|
b := "1"
|
|
|
|
"#,
|
|
|
|
r#"a := "0"
|
|
|
|
|
|
|
|
b := "1"
|
|
|
|
|
|
|
|
c := a + b + a + b"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_assignment_backticks,
|
|
|
|
"a := `echo hello`
|
|
|
|
c := a + b + a + b
|
|
|
|
b := `echo goodbye`",
|
|
|
|
"a := `echo hello`
|
|
|
|
|
|
|
|
b := `echo goodbye`
|
|
|
|
|
|
|
|
c := a + b + a + b",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parse_interpolation_backticks,
|
|
|
|
r#"a:
|
|
|
|
echo {{ `echo hello` + "blarg" }} {{ `echo bob` }}"#,
|
|
|
|
r#"a:
|
|
|
|
echo {{`echo hello` + "blarg"}} {{`echo bob`}}"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
eof_test,
|
|
|
|
"x:\ny:\nz:\na b c: x y z",
|
|
|
|
"a b c: x y z\n\nx:\n\ny:\n\nz:",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
string_quote_escape,
|
|
|
|
r#"a := "hello\"""#,
|
|
|
|
r#"a := "hello\"""#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
string_escapes,
|
|
|
|
r#"a := "\n\t\r\"\\""#,
|
|
|
|
r#"a := "\n\t\r\"\\""#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parameters,
|
|
|
|
"a b c:
|
|
|
|
{{b}} {{c}}",
|
|
|
|
"a b c:
|
|
|
|
{{b}} {{c}}",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
unary_functions,
|
|
|
|
"
|
|
|
|
x := arch()
|
|
|
|
|
|
|
|
a:
|
|
|
|
{{os()}} {{os_family()}}",
|
|
|
|
"x := arch()
|
|
|
|
|
|
|
|
a:
|
|
|
|
{{os()}} {{os_family()}}",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
env_functions,
|
|
|
|
r#"
|
|
|
|
x := env_var('foo',)
|
|
|
|
|
|
|
|
a:
|
|
|
|
{{env_var_or_default('foo' + 'bar', 'baz',)}} {{env_var(env_var("baz"))}}"#,
|
|
|
|
r#"x := env_var('foo')
|
|
|
|
|
|
|
|
a:
|
|
|
|
{{env_var_or_default('foo' + 'bar', 'baz')}} {{env_var(env_var("baz"))}}"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parameter_default_string,
|
|
|
|
r#"
|
|
|
|
f x="abc":
|
|
|
|
"#,
|
|
|
|
r#"f x="abc":"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parameter_default_raw_string,
|
|
|
|
r#"
|
|
|
|
f x='abc':
|
|
|
|
"#,
|
|
|
|
r#"f x='abc':"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parameter_default_backtick,
|
|
|
|
r#"
|
|
|
|
f x=`echo hello`:
|
|
|
|
"#,
|
|
|
|
r#"f x=`echo hello`:"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parameter_default_concatination_string,
|
|
|
|
r#"
|
|
|
|
f x=(`echo hello` + "foo"):
|
|
|
|
"#,
|
|
|
|
r#"f x=(`echo hello` + "foo"):"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parameter_default_concatination_variable,
|
|
|
|
r#"
|
|
|
|
x := "10"
|
|
|
|
f y=(`echo hello` + x) +z="foo":
|
|
|
|
"#,
|
|
|
|
r#"x := "10"
|
|
|
|
|
|
|
|
f y=(`echo hello` + x) +z="foo":"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
parameter_default_multiple,
|
|
|
|
r#"
|
|
|
|
x := "10"
|
|
|
|
f y=(`echo hello` + x) +z=("foo" + "bar"):
|
|
|
|
"#,
|
|
|
|
r#"x := "10"
|
|
|
|
|
|
|
|
f y=(`echo hello` + x) +z=("foo" + "bar"):"#,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
concatination_in_group,
|
|
|
|
"x := ('0' + '1')",
|
|
|
|
"x := ('0' + '1')",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
string_in_group,
|
|
|
|
"x := ('0' )",
|
|
|
|
"x := ('0')",
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
test! {
|
|
|
|
escaped_dos_newlines,
|
|
|
|
"@spam:\r
|
|
|
|
\t{ \\\r
|
|
|
|
\t\tfiglet test; \\\r
|
|
|
|
\t\tcargo build --color always 2>&1; \\\r
|
|
|
|
\t\tcargo test --color always -- --color always 2>&1; \\\r
|
|
|
|
\t} | less\r
|
|
|
|
",
|
|
|
|
"@spam:
|
|
|
|
{ \\
|
|
|
|
\tfiglet test; \\
|
|
|
|
\tcargo build --color always 2>&1; \\
|
|
|
|
\tcargo test --color always -- --color always 2>&1; \\
|
|
|
|
} | less",
|
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|