2022-12-27 20:16:18 -08:00
|
|
|
use {super::*, serde::Serialize};
|
2021-11-17 00:07:48 -08:00
|
|
|
|
2023-12-27 20:27:15 -08:00
|
|
|
#[derive(Debug)]
|
|
|
|
struct Invocation<'src: 'run, 'run> {
|
2023-12-31 14:03:49 -08:00
|
|
|
arguments: Vec<&'run str>,
|
2024-05-28 20:06:30 -07:00
|
|
|
module_source: &'run Path,
|
2023-12-27 20:27:15 -08:00
|
|
|
recipe: &'run Recipe<'src>,
|
|
|
|
scope: &'run Scope<'src, 'run>,
|
2024-05-28 20:06:30 -07:00
|
|
|
settings: &'run Settings<'src>,
|
2023-12-27 20:27:15 -08:00
|
|
|
}
|
|
|
|
|
2021-11-17 00:07:48 -08:00
|
|
|
#[derive(Debug, PartialEq, Serialize)]
|
2019-11-10 23:17:47 -08:00
|
|
|
pub(crate) struct Justfile<'src> {
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) aliases: Table<'src, Alias<'src>>,
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) assignments: Table<'src, Assignment<'src>>,
|
2023-11-22 10:33:55 -08:00
|
|
|
#[serde(rename = "first", serialize_with = "keyed::serialize_option")]
|
|
|
|
pub(crate) default: Option<Rc<Recipe<'src>>>,
|
2023-11-24 23:15:41 -08:00
|
|
|
#[serde(skip)]
|
|
|
|
pub(crate) loaded: Vec<PathBuf>,
|
2024-05-25 01:01:37 -07:00
|
|
|
pub(crate) modules: Table<'src, Justfile<'src>>,
|
|
|
|
#[serde(skip)]
|
|
|
|
pub(crate) name: Option<Name<'src>>,
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) recipes: Table<'src, Rc<Recipe<'src>>>,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) settings: Settings<'src>,
|
2024-05-28 20:06:30 -07:00
|
|
|
#[serde(skip)]
|
|
|
|
pub(crate) source: PathBuf,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) warnings: Vec<Warning>,
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2019-11-10 23:17:47 -08:00
|
|
|
impl<'src> Justfile<'src> {
|
2021-07-26 01:26:06 -07:00
|
|
|
pub(crate) fn suggest_recipe(&self, input: &str) -> Option<Suggestion<'src>> {
|
2018-08-27 16:03:52 -07:00
|
|
|
let mut suggestions = self
|
|
|
|
.recipes
|
|
|
|
.keys()
|
2020-04-26 14:19:21 -07:00
|
|
|
.map(|name| {
|
2021-09-16 06:44:40 -07:00
|
|
|
(
|
|
|
|
edit_distance(name, input),
|
|
|
|
Suggestion { name, target: None },
|
|
|
|
)
|
2020-04-26 14:19:21 -07:00
|
|
|
})
|
|
|
|
.chain(self.aliases.iter().map(|(name, alias)| {
|
2021-09-16 06:44:40 -07:00
|
|
|
(
|
|
|
|
edit_distance(name, input),
|
|
|
|
Suggestion {
|
|
|
|
name,
|
|
|
|
target: Some(alias.target.name.lexeme()),
|
|
|
|
},
|
|
|
|
)
|
2020-04-26 14:19:21 -07:00
|
|
|
}))
|
|
|
|
.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
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
pub(crate) fn suggest_variable(&self, input: &str) -> Option<Suggestion<'src>> {
|
2021-04-25 17:02:57 -07:00
|
|
|
let mut suggestions = self
|
|
|
|
.assignments
|
|
|
|
.keys()
|
|
|
|
.map(|name| {
|
2021-09-16 06:44:40 -07:00
|
|
|
(
|
|
|
|
edit_distance(name, input),
|
|
|
|
Suggestion { name, target: None },
|
|
|
|
)
|
2021-04-25 17:02:57 -07:00
|
|
|
})
|
|
|
|
.filter(|(distance, _suggestion)| distance < &3)
|
|
|
|
.collect::<Vec<(usize, Suggestion)>>();
|
|
|
|
suggestions.sort_by_key(|(distance, _suggestion)| *distance);
|
|
|
|
|
|
|
|
suggestions
|
|
|
|
.into_iter()
|
|
|
|
.map(|(_distance, suggestion)| suggestion)
|
|
|
|
.next()
|
|
|
|
}
|
|
|
|
|
2023-12-27 20:27:15 -08:00
|
|
|
fn scope<'run>(
|
|
|
|
&'run self,
|
|
|
|
config: &'run Config,
|
|
|
|
dotenv: &'run BTreeMap<String, String>,
|
|
|
|
search: &'run Search,
|
|
|
|
overrides: &BTreeMap<String, String>,
|
|
|
|
parent: &'run Scope<'src, 'run>,
|
|
|
|
) -> RunResult<'src, Scope<'src, 'run>>
|
|
|
|
where
|
|
|
|
'src: 'run,
|
|
|
|
{
|
|
|
|
let mut scope = parent.child();
|
|
|
|
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.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !unknown_overrides.is_empty() {
|
|
|
|
return Err(Error::UnknownOverrides {
|
|
|
|
overrides: unknown_overrides,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Evaluator::evaluate_assignments(
|
|
|
|
&self.assignments,
|
|
|
|
config,
|
|
|
|
dotenv,
|
2024-05-28 20:06:30 -07:00
|
|
|
&self.source,
|
2023-12-27 20:27:15 -08:00
|
|
|
scope,
|
|
|
|
search,
|
2024-05-28 20:06:30 -07:00
|
|
|
&self.settings,
|
2023-12-27 20:27:15 -08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
pub(crate) fn run(
|
|
|
|
&self,
|
|
|
|
config: &Config,
|
|
|
|
search: &Search,
|
|
|
|
overrides: &BTreeMap<String, String>,
|
|
|
|
arguments: &[String],
|
2023-12-29 12:16:31 -08:00
|
|
|
) -> RunResult<'src> {
|
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()))
|
2021-07-26 01:26:06 -07:00
|
|
|
.cloned()
|
|
|
|
.collect::<Vec<String>>();
|
2017-11-16 23:30:08 -08:00
|
|
|
|
|
|
|
if !unknown_overrides.is_empty() {
|
2021-07-26 01:26:06 -07:00
|
|
|
return Err(Error::UnknownOverrides {
|
2018-08-27 16:03:52 -07:00
|
|
|
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 {
|
2022-01-30 12:16:10 -08:00
|
|
|
load_dotenv(config, &self.settings, &search.working_directory)?
|
2020-05-23 20:41:12 -07:00
|
|
|
} else {
|
|
|
|
BTreeMap::new()
|
|
|
|
};
|
2018-03-05 13:21:35 -08:00
|
|
|
|
2024-05-18 16:12:11 -07:00
|
|
|
let root = Scope::root();
|
2019-12-07 03:09:21 -08:00
|
|
|
|
2023-12-27 20:27:15 -08:00
|
|
|
let scope = self.scope(config, &dotenv, search, overrides, &root)?;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2021-05-09 20:35:35 -07:00
|
|
|
match &config.subcommand {
|
|
|
|
Subcommand::Command {
|
|
|
|
binary, arguments, ..
|
|
|
|
} => {
|
|
|
|
let mut command = if config.shell_command {
|
2022-01-30 12:16:10 -08:00
|
|
|
let mut command = self.settings.shell_command(config);
|
2021-05-09 20:35:35 -07:00
|
|
|
command.arg(binary);
|
|
|
|
command
|
2021-04-25 17:02:57 -07:00
|
|
|
} else {
|
2021-05-09 20:35:35 -07:00
|
|
|
Command::new(binary)
|
|
|
|
};
|
|
|
|
|
|
|
|
command.args(arguments);
|
|
|
|
|
|
|
|
command.current_dir(&search.working_directory);
|
|
|
|
|
|
|
|
let scope = scope.child();
|
|
|
|
|
|
|
|
command.export(&self.settings, &dotenv, &scope);
|
|
|
|
|
|
|
|
let status = InterruptHandler::guard(|| command.status()).map_err(|io_error| {
|
2021-07-26 01:26:06 -07:00
|
|
|
Error::CommandInvoke {
|
2021-05-09 20:35:35 -07:00
|
|
|
binary: binary.clone(),
|
|
|
|
arguments: arguments.clone(),
|
|
|
|
io_error,
|
|
|
|
}
|
|
|
|
})?;
|
|
|
|
|
|
|
|
if !status.success() {
|
2021-07-26 01:26:06 -07:00
|
|
|
return Err(Error::CommandStatus {
|
|
|
|
binary: binary.clone(),
|
|
|
|
arguments: arguments.clone(),
|
|
|
|
status,
|
|
|
|
});
|
2021-05-09 20:35:35 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return Ok(());
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-05-09 20:35:35 -07:00
|
|
|
Subcommand::Evaluate { variable, .. } => {
|
|
|
|
if let Some(variable) = variable {
|
|
|
|
if let Some(value) = scope.value(variable) {
|
2022-12-15 16:53:21 -08:00
|
|
|
print!("{value}");
|
2021-05-09 20:35:35 -07:00
|
|
|
} else {
|
2021-07-26 01:26:06 -07:00
|
|
|
return Err(Error::EvalUnknownVariable {
|
2022-01-30 12:16:10 -08:00
|
|
|
suggestion: self.suggest_variable(variable),
|
2021-09-16 06:44:40 -07:00
|
|
|
variable: variable.clone(),
|
2021-05-09 20:35:35 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let mut width = 0;
|
|
|
|
|
|
|
|
for name in scope.names() {
|
|
|
|
width = cmp::max(name.len(), width);
|
|
|
|
}
|
|
|
|
|
|
|
|
for binding in scope.bindings() {
|
|
|
|
println!(
|
|
|
|
"{0:1$} := \"{2}\"",
|
|
|
|
binding.name.lexeme(),
|
|
|
|
width,
|
|
|
|
binding.value
|
|
|
|
);
|
|
|
|
}
|
2021-04-25 17:02:57 -07:00
|
|
|
}
|
2021-04-05 21:50:50 -07:00
|
|
|
|
2021-05-09 20:35:35 -07:00
|
|
|
return Ok(());
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
|
|
|
_ => {}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2023-12-31 14:03:49 -08:00
|
|
|
let mut remaining: Vec<&str> = if !arguments.is_empty() {
|
2021-04-05 21:17:53 -07:00
|
|
|
arguments.iter().map(String::as_str).collect()
|
2023-11-22 10:33:55 -08:00
|
|
|
} else if let Some(recipe) = &self.default {
|
2023-12-27 20:27:15 -08:00
|
|
|
recipe.check_can_be_default_recipe()?;
|
2021-04-05 21:17:53 -07:00
|
|
|
vec![recipe.name()]
|
2023-11-22 10:27:49 -08:00
|
|
|
} else if self.recipes.is_empty() {
|
2021-07-26 01:26:06 -07:00
|
|
|
return Err(Error::NoRecipes);
|
2023-11-22 10:27:49 -08:00
|
|
|
} else {
|
|
|
|
return Err(Error::NoDefaultRecipe);
|
2021-04-05 21:17:53 -07:00
|
|
|
};
|
|
|
|
|
2023-12-27 20:27:15 -08:00
|
|
|
let mut missing = Vec::new();
|
|
|
|
let mut invocations = Vec::new();
|
|
|
|
let mut scopes = BTreeMap::new();
|
|
|
|
let arena: Arena<Scope> = Arena::new();
|
|
|
|
|
2023-12-31 14:03:49 -08:00
|
|
|
while let Some(first) = remaining.first().copied() {
|
2023-12-31 16:15:41 -08:00
|
|
|
if first.contains("::")
|
|
|
|
&& !(first.starts_with(':') || first.ends_with(':') || first.contains(":::"))
|
|
|
|
{
|
2023-12-31 14:03:49 -08:00
|
|
|
remaining = first
|
|
|
|
.split("::")
|
|
|
|
.chain(remaining[1..].iter().copied())
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let rest = &remaining[1..];
|
|
|
|
|
2023-12-27 20:27:15 -08:00
|
|
|
if let Some((invocation, consumed)) = self.invocation(
|
|
|
|
0,
|
|
|
|
&mut Vec::new(),
|
|
|
|
&arena,
|
|
|
|
&mut scopes,
|
|
|
|
config,
|
|
|
|
&dotenv,
|
|
|
|
search,
|
|
|
|
&scope,
|
|
|
|
first,
|
|
|
|
rest,
|
|
|
|
)? {
|
2023-12-31 14:03:49 -08:00
|
|
|
remaining = rest[consumed..].to_vec();
|
2023-12-27 20:27:15 -08:00
|
|
|
invocations.push(invocation);
|
2017-11-16 23:30:08 -08:00
|
|
|
} else {
|
2023-12-31 14:03:49 -08:00
|
|
|
missing.push(first.to_string());
|
|
|
|
remaining = rest.to_vec();
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !missing.is_empty() {
|
|
|
|
let suggestion = if missing.len() == 1 {
|
2021-04-25 17:02:57 -07:00
|
|
|
self.suggest_recipe(missing.first().unwrap())
|
2017-11-16 23:30:08 -08:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2021-07-26 01:26:06 -07:00
|
|
|
return Err(Error::UnknownRecipes {
|
2018-08-27 16:03:52 -07:00
|
|
|
recipes: missing,
|
|
|
|
suggestion,
|
|
|
|
});
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2024-01-08 13:26:33 -08:00
|
|
|
let mut ran = Ran::default();
|
2023-12-27 20:27:15 -08:00
|
|
|
for invocation in invocations {
|
|
|
|
let context = RecipeContext {
|
|
|
|
config,
|
2024-05-28 20:06:30 -07:00
|
|
|
dotenv: &dotenv,
|
|
|
|
module_source: invocation.module_source,
|
2023-12-27 20:27:15 -08:00
|
|
|
scope: invocation.scope,
|
|
|
|
search,
|
2024-05-28 20:06:30 -07:00
|
|
|
settings: invocation.settings,
|
2023-12-27 20:27:15 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
Self::run_recipe(
|
2024-01-08 13:26:33 -08:00
|
|
|
&invocation
|
|
|
|
.arguments
|
|
|
|
.iter()
|
|
|
|
.copied()
|
|
|
|
.map(str::to_string)
|
|
|
|
.collect::<Vec<String>>(),
|
2024-01-09 00:40:08 -08:00
|
|
|
&context,
|
2023-12-27 20:27:15 -08:00
|
|
|
&mut ran,
|
2024-01-09 00:40:08 -08:00
|
|
|
invocation.recipe,
|
|
|
|
search,
|
2023-12-27 20:27:15 -08:00
|
|
|
)?;
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
pub(crate) fn get_alias(&self, name: &str) -> Option<&Alias<'src>> {
|
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>> {
|
2021-05-07 00:14:38 -07:00
|
|
|
self
|
|
|
|
.recipes
|
|
|
|
.get(name)
|
|
|
|
.map(Rc::as_ref)
|
|
|
|
.or_else(|| self.aliases.get(name).map(|alias| alias.target.as_ref()))
|
2019-05-15 12:43:47 -07:00
|
|
|
}
|
|
|
|
|
2023-12-27 20:27:15 -08:00
|
|
|
fn invocation<'run>(
|
|
|
|
&'run self,
|
|
|
|
depth: usize,
|
|
|
|
path: &mut Vec<&'run str>,
|
|
|
|
arena: &'run Arena<Scope<'src, 'run>>,
|
|
|
|
scopes: &mut BTreeMap<Vec<&'run str>, &'run Scope<'src, 'run>>,
|
|
|
|
config: &'run Config,
|
|
|
|
dotenv: &'run BTreeMap<String, String>,
|
|
|
|
search: &'run Search,
|
|
|
|
parent: &'run Scope<'src, 'run>,
|
|
|
|
first: &'run str,
|
2023-12-31 14:03:49 -08:00
|
|
|
rest: &[&'run str],
|
2023-12-27 20:27:15 -08:00
|
|
|
) -> RunResult<'src, Option<(Invocation<'src, 'run>, usize)>> {
|
|
|
|
if let Some(module) = self.modules.get(first) {
|
|
|
|
path.push(first);
|
|
|
|
|
|
|
|
let scope = if let Some(scope) = scopes.get(path) {
|
|
|
|
scope
|
|
|
|
} else {
|
|
|
|
let scope = module.scope(config, dotenv, search, &BTreeMap::new(), parent)?;
|
|
|
|
let scope = arena.alloc(scope);
|
|
|
|
scopes.insert(path.clone(), scope);
|
|
|
|
scopes.get(path).unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
if rest.is_empty() {
|
|
|
|
if let Some(recipe) = &module.default {
|
|
|
|
recipe.check_can_be_default_recipe()?;
|
|
|
|
return Ok(Some((
|
|
|
|
Invocation {
|
|
|
|
settings: &module.settings,
|
|
|
|
recipe,
|
2023-12-31 14:03:49 -08:00
|
|
|
arguments: Vec::new(),
|
2023-12-27 20:27:15 -08:00
|
|
|
scope,
|
2024-05-28 20:06:30 -07:00
|
|
|
module_source: &self.source,
|
2023-12-27 20:27:15 -08:00
|
|
|
},
|
|
|
|
depth,
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
Err(Error::NoDefaultRecipe)
|
|
|
|
} else {
|
|
|
|
module.invocation(
|
|
|
|
depth + 1,
|
|
|
|
path,
|
|
|
|
arena,
|
|
|
|
scopes,
|
|
|
|
config,
|
|
|
|
dotenv,
|
|
|
|
search,
|
|
|
|
scope,
|
|
|
|
rest[0],
|
|
|
|
&rest[1..],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else if let Some(recipe) = self.get_recipe(first) {
|
|
|
|
if recipe.parameters.is_empty() {
|
|
|
|
Ok(Some((
|
|
|
|
Invocation {
|
2023-12-31 14:03:49 -08:00
|
|
|
arguments: Vec::new(),
|
2023-12-27 20:27:15 -08:00
|
|
|
recipe,
|
|
|
|
scope: parent,
|
|
|
|
settings: &self.settings,
|
2024-05-28 20:06:30 -07:00
|
|
|
module_source: &self.source,
|
2023-12-27 20:27:15 -08:00
|
|
|
},
|
|
|
|
depth,
|
|
|
|
)))
|
|
|
|
} else {
|
|
|
|
let argument_range = recipe.argument_range();
|
|
|
|
let argument_count = cmp::min(rest.len(), recipe.max_arguments());
|
|
|
|
if !argument_range.range_contains(&argument_count) {
|
|
|
|
return Err(Error::ArgumentCountMismatch {
|
|
|
|
recipe: recipe.name(),
|
|
|
|
parameters: recipe.parameters.clone(),
|
|
|
|
found: rest.len(),
|
|
|
|
min: recipe.min_arguments(),
|
|
|
|
max: recipe.max_arguments(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Ok(Some((
|
|
|
|
Invocation {
|
2023-12-31 14:03:49 -08:00
|
|
|
arguments: rest[..argument_count].to_vec(),
|
2023-12-27 20:27:15 -08:00
|
|
|
recipe,
|
|
|
|
scope: parent,
|
|
|
|
settings: &self.settings,
|
2024-05-28 20:06:30 -07:00
|
|
|
module_source: &self.source,
|
2023-12-27 20:27:15 -08:00
|
|
|
},
|
|
|
|
depth + argument_count,
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-25 01:01:37 -07:00
|
|
|
pub(crate) fn name(&self) -> &'src str {
|
|
|
|
self.name.map(|name| name.lexeme()).unwrap_or_default()
|
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
fn run_recipe(
|
2024-01-08 13:26:33 -08:00
|
|
|
arguments: &[String],
|
2024-01-09 00:40:08 -08:00
|
|
|
context: &RecipeContext<'src, '_>,
|
2024-01-08 13:26:33 -08:00
|
|
|
ran: &mut Ran<'src>,
|
2024-01-09 00:40:08 -08:00
|
|
|
recipe: &Recipe<'src>,
|
|
|
|
search: &Search,
|
2023-12-29 12:16:31 -08:00
|
|
|
) -> RunResult<'src> {
|
2024-01-08 13:26:33 -08:00
|
|
|
if ran.has_run(&recipe.namepath, arguments) {
|
2022-05-03 22:04:55 -07:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2023-11-16 15:51:34 -08:00
|
|
|
if !context.config.yes && !recipe.confirm()? {
|
|
|
|
return Err(Error::NotConfirmed {
|
|
|
|
recipe: recipe.name(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-02 03:25:43 -07:00
|
|
|
let (outer, positional) = Evaluator::evaluate_parameters(
|
2024-05-28 20:06:30 -07:00
|
|
|
arguments,
|
2019-12-07 04:03:03 -08:00
|
|
|
context.config,
|
2024-05-28 20:06:30 -07:00
|
|
|
context.dotenv,
|
|
|
|
context.module_source,
|
2019-12-07 04:03:03 -08:00
|
|
|
&recipe.parameters,
|
2023-12-27 20:27:15 -08:00
|
|
|
context.scope,
|
2019-12-25 06:12:06 -08:00
|
|
|
search,
|
2024-05-28 20:06:30 -07:00
|
|
|
context.settings,
|
2019-12-07 04:03:03 -08:00
|
|
|
)?;
|
|
|
|
|
2021-03-25 17:00:32 -07:00
|
|
|
let scope = outer.child();
|
|
|
|
|
2024-05-28 20:06:30 -07:00
|
|
|
let mut evaluator = Evaluator::recipe_evaluator(
|
|
|
|
context.config,
|
|
|
|
context.dotenv,
|
|
|
|
context.module_source,
|
|
|
|
&scope,
|
|
|
|
search,
|
|
|
|
context.settings,
|
|
|
|
);
|
2019-12-07 04:03:03 -08:00
|
|
|
|
2024-01-09 00:40:08 -08:00
|
|
|
if !context.config.no_dependencies {
|
|
|
|
for Dependency { recipe, arguments } in recipe.dependencies.iter().take(recipe.priors) {
|
|
|
|
let arguments = arguments
|
|
|
|
.iter()
|
|
|
|
.map(|argument| evaluator.evaluate_expression(argument))
|
|
|
|
.collect::<RunResult<Vec<String>>>()?;
|
2022-05-03 22:04:55 -07:00
|
|
|
|
2024-05-28 20:06:30 -07:00
|
|
|
Self::run_recipe(&arguments, context, ran, recipe, search)?;
|
2024-01-09 00:40:08 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-12-07 04:03:03 -08:00
|
|
|
|
2024-05-28 20:06:30 -07:00
|
|
|
recipe.run(context, &scope, &positional)?;
|
2019-12-07 04:03:03 -08:00
|
|
|
|
2024-01-09 00:40:08 -08:00
|
|
|
if !context.config.no_dependencies {
|
2024-01-08 13:26:33 -08:00
|
|
|
let mut ran = Ran::default();
|
2021-07-22 00:20:25 -07:00
|
|
|
|
|
|
|
for Dependency { recipe, arguments } in recipe.dependencies.iter().skip(recipe.priors) {
|
|
|
|
let mut evaluated = Vec::new();
|
|
|
|
|
|
|
|
for argument in arguments {
|
|
|
|
evaluated.push(evaluator.evaluate_expression(argument)?);
|
|
|
|
}
|
|
|
|
|
2024-05-28 20:06:30 -07:00
|
|
|
Self::run_recipe(&evaluated, context, &mut ran, recipe, search)?;
|
2021-07-22 00:20:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 13:26:33 -08:00
|
|
|
ran.ran(&recipe.namepath, arguments.to_vec());
|
2024-05-28 20:06:30 -07:00
|
|
|
|
2017-11-16 23:30:08 -08:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-08-21 15:13:54 -07:00
|
|
|
|
2024-05-25 01:01:37 -07:00
|
|
|
pub(crate) fn modules(&self, config: &Config) -> Vec<&Justfile> {
|
|
|
|
let mut modules = self.modules.values().collect::<Vec<&Justfile>>();
|
|
|
|
|
|
|
|
if config.unsorted {
|
|
|
|
modules.sort_by_key(|module| {
|
|
|
|
module
|
|
|
|
.name
|
|
|
|
.map(|name| name.token.offset)
|
|
|
|
.unwrap_or_default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
modules
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn public_recipes(&self, config: &Config) -> Vec<&Recipe<'src, Dependency>> {
|
2020-08-21 15:13:54 -07:00
|
|
|
let mut recipes = self
|
|
|
|
.recipes
|
|
|
|
.values()
|
|
|
|
.map(AsRef::as_ref)
|
2024-01-09 00:07:43 -08:00
|
|
|
.filter(|recipe| recipe.is_public())
|
2020-08-21 15:13:54 -07:00
|
|
|
.collect::<Vec<&Recipe<Dependency>>>();
|
|
|
|
|
2024-05-25 01:01:37 -07:00
|
|
|
if config.unsorted {
|
2024-05-25 18:10:06 -07:00
|
|
|
recipes.sort_by_key(|recipe| (&recipe.import_offsets, recipe.name.offset));
|
2020-08-21 15:13:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
recipes
|
|
|
|
}
|
2024-05-25 00:32:25 -07:00
|
|
|
|
|
|
|
pub(crate) fn public_groups(&self) -> BTreeSet<String> {
|
|
|
|
self
|
|
|
|
.recipes
|
|
|
|
.values()
|
|
|
|
.map(AsRef::as_ref)
|
|
|
|
.filter(|recipe| recipe.is_public())
|
|
|
|
.flat_map(Recipe::groups)
|
|
|
|
.collect()
|
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2021-07-28 18:06:57 -07:00
|
|
|
impl<'src> ColorDisplay for Justfile<'src> {
|
|
|
|
fn fmt(&self, f: &mut Formatter, color: Color) -> 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 ")?;
|
|
|
|
}
|
2022-12-15 16:53: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() {
|
2022-12-15 16:53:21 -08: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() {
|
2021-07-28 18:06:57 -07:00
|
|
|
write!(f, "{}", recipe.color_display(color))?;
|
2017-11-16 23:30:08 -08:00
|
|
|
items -= 1;
|
|
|
|
if items != 0 {
|
|
|
|
write!(f, "\n\n")?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-25 01:01:37 -07:00
|
|
|
impl<'src> Keyed<'src> for Justfile<'src> {
|
|
|
|
fn key(&self) -> &'src str {
|
|
|
|
self.name()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:30:08 -08:00
|
|
|
#[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;
|
2021-07-26 01:26:06 -07:00
|
|
|
use Error::*;
|
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_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"),
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2022-10-31 00:52:03 -07:00
|
|
|
print_message,
|
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
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipe, "fail");
|
|
|
|
assert_eq!(code, 100);
|
|
|
|
assert_eq!(line_number, Some(2));
|
2022-10-31 00:52:03 -07:00
|
|
|
assert!(print_message);
|
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,
|
2022-10-31 00:52:03 -07:00
|
|
|
print_message,
|
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
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipe, "a");
|
|
|
|
assert_eq!(code, 150);
|
|
|
|
assert_eq!(line_number, Some(2));
|
2022-10-31 00:52:03 -07:00
|
|
|
assert!(print_message);
|
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#"
|
2021-03-28 23:39:23 -07:00
|
|
|
export foo := "a"
|
|
|
|
baz := "c"
|
|
|
|
export bar := "b"
|
|
|
|
export abc := foo + bar + baz
|
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
|
|
|
|
|
|
|
wut:
|
|
|
|
echo $foo $bar $baz
|
|
|
|
"#,
|
|
|
|
args: ["--quiet", "wut"],
|
|
|
|
error: Code {
|
|
|
|
recipe,
|
2022-10-25 16:32:36 -07:00
|
|
|
line_number,
|
2022-10-31 00:52:03 -07:00
|
|
|
print_message,
|
2021-05-07 00:14:38 -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
|
|
|
},
|
|
|
|
check: {
|
|
|
|
assert_eq!(recipe, "wut");
|
|
|
|
assert_eq!(line_number, Some(7));
|
2022-10-31 00:52:03 -07:00
|
|
|
assert!(print_message);
|
2017-11-17 17:28:06 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
fn case(input: &str, expected: &str) {
|
2019-11-07 10:55:15 -08:00
|
|
|
let justfile = compile(input);
|
2021-07-28 18:06:57 -07:00
|
|
|
let actual = format!("{}", justfile.color_display(Color::never()));
|
2019-11-07 10:55:15 -08:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
println!("Re-parsing...");
|
|
|
|
let reparsed = compile(&actual);
|
2021-07-28 18:06:57 -07:00
|
|
|
let redumped = format!("{}", reparsed.color_display(Color::never()));
|
2019-11-07 10:55:15 -08:00
|
|
|
assert_eq!(redumped, actual);
|
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_empty() {
|
|
|
|
case(
|
|
|
|
"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
# hello
|
|
|
|
|
|
|
|
|
|
|
|
",
|
2023-11-16 13:51:57 -08:00
|
|
|
"",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_string_default() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo a="b\t":
|
|
|
|
|
|
|
|
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"foo a="b\t":"#,
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_multiple() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
a:
|
|
|
|
b:
|
2023-11-16 13:51:57 -08:00
|
|
|
", r"a:
|
2019-11-07 10:55:15 -08:00
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
b:",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_variadic() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo +a:
|
|
|
|
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
",
|
|
|
|
r"foo +a:",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_variadic_string_default() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo +a="Hello":
|
|
|
|
|
|
|
|
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"foo +a="Hello":"#,
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_raw_string_default() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo a='b\t':
|
|
|
|
|
|
|
|
|
2023-10-08 19:34:05 -07:00
|
|
|
",
|
2023-11-16 13:51:57 -08:00
|
|
|
r"foo a='b\t':",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_export() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
export a := "hello"
|
|
|
|
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"export a := "hello""#,
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_alias_after_target() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
foo:
|
|
|
|
echo a
|
|
|
|
alias f := foo
|
2023-11-16 13:51:57 -08:00
|
|
|
",
|
|
|
|
r"alias f := foo
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo:
|
2023-11-16 13:51:57 -08:00
|
|
|
echo a",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_alias_before_target() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
alias f := foo
|
|
|
|
foo:
|
|
|
|
echo a
|
2023-11-16 13:51:57 -08:00
|
|
|
",
|
|
|
|
r"alias f := foo
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo:
|
2023-11-16 13:51:57 -08:00
|
|
|
echo a",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_alias_with_comment() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
alias f := foo #comment
|
|
|
|
foo:
|
|
|
|
echo a
|
2023-11-16 13:51:57 -08:00
|
|
|
",
|
|
|
|
r"alias f := foo
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo:
|
2023-11-16 13:51:57 -08:00
|
|
|
echo a",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_complex() {
|
|
|
|
case(
|
|
|
|
"
|
2019-11-07 10:55:15 -08:00
|
|
|
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
|
|
|
|
",
|
2023-11-16 13:51:57 -08:00
|
|
|
"bar := foo
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
foo := \"xx\"
|
|
|
|
|
|
|
|
goodbye := \"y\"
|
|
|
|
|
|
|
|
hello a b c: x y z
|
|
|
|
#! blah
|
|
|
|
#blarg
|
2021-06-08 01:01:27 -07:00
|
|
|
{{ foo + bar }}abc{{ goodbye + \"x\" }}xyz
|
2019-11-07 10:55:15 -08:00
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
|
|
|
|
x:
|
|
|
|
|
|
|
|
y:
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
z:",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_shebang() {
|
|
|
|
case(
|
|
|
|
"
|
2019-11-07 10:55:15 -08:00
|
|
|
practicum := 'hello'
|
|
|
|
install:
|
|
|
|
\t#!/bin/sh
|
|
|
|
\tif [[ -f {{practicum}} ]]; then
|
|
|
|
\t\treturn
|
|
|
|
\tfi
|
|
|
|
",
|
2023-11-16 13:51:57 -08:00
|
|
|
"practicum := 'hello'
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
install:
|
|
|
|
#!/bin/sh
|
2021-06-08 01:01:27 -07:00
|
|
|
if [[ -f {{ practicum }} ]]; then
|
2019-11-07 10:55:15 -08:00
|
|
|
\treturn
|
|
|
|
fi",
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_simple_shebang() {
|
|
|
|
case("a:\n #!\n print(1)", "a:\n #!\n print(1)");
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_assignments() {
|
|
|
|
case(
|
|
|
|
r#"a := "0"
|
2019-11-07 10:55:15 -08:00
|
|
|
c := a + b + a + b
|
|
|
|
b := "1"
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"a := "0"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
b := "1"
|
|
|
|
|
|
|
|
c := a + b + a + b"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_assignment_backticks() {
|
|
|
|
case(
|
|
|
|
"a := `echo hello`
|
2019-11-07 10:55:15 -08:00
|
|
|
c := a + b + a + b
|
|
|
|
b := `echo goodbye`",
|
2023-11-16 13:51:57 -08:00
|
|
|
"a := `echo hello`
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
b := `echo goodbye`
|
|
|
|
|
|
|
|
c := a + b + a + b",
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parse_interpolation_backticks() {
|
|
|
|
case(
|
|
|
|
r#"a:
|
2019-11-07 10:55:15 -08:00
|
|
|
echo {{ `echo hello` + "blarg" }} {{ `echo bob` }}"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"a:
|
2021-06-08 01:01:27 -07:00
|
|
|
echo {{ `echo hello` + "blarg" }} {{ `echo bob` }}"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn eof_test() {
|
|
|
|
case("x:\ny:\nz:\na b c: x y z", "a b c: x y z\n\nx:\n\ny:\n\nz:");
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn string_quote_escape() {
|
|
|
|
case(r#"a := "hello\"""#, r#"a := "hello\"""#);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn string_escapes() {
|
|
|
|
case(r#"a := "\n\t\r\"\\""#, r#"a := "\n\t\r\"\\""#);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parameters() {
|
|
|
|
case(
|
|
|
|
"a b c:
|
2019-11-07 10:55:15 -08:00
|
|
|
{{b}} {{c}}",
|
2023-11-16 13:51:57 -08:00
|
|
|
"a b c:
|
2021-06-08 01:01:27 -07:00
|
|
|
{{ b }} {{ c }}",
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn unary_functions() {
|
|
|
|
case(
|
|
|
|
"
|
2019-11-07 10:55:15 -08:00
|
|
|
x := arch()
|
|
|
|
|
|
|
|
a:
|
2023-08-02 16:52:21 -07:00
|
|
|
{{os()}} {{os_family()}} {{num_cpus()}}",
|
2023-11-16 13:51:57 -08:00
|
|
|
"x := arch()
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
a:
|
2023-08-02 16:52:21 -07:00
|
|
|
{{ os() }} {{ os_family() }} {{ num_cpus() }}",
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn env_functions() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
x := env_var('foo',)
|
|
|
|
|
|
|
|
a:
|
|
|
|
{{env_var_or_default('foo' + 'bar', 'baz',)}} {{env_var(env_var("baz"))}}"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"x := env_var('foo')
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
a:
|
2021-06-08 01:01:27 -07:00
|
|
|
{{ env_var_or_default('foo' + 'bar', 'baz') }} {{ env_var(env_var("baz")) }}"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parameter_default_string() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
f x="abc":
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"f x="abc":"#,
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parameter_default_raw_string() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
f x='abc':
|
2023-11-16 13:51:57 -08:00
|
|
|
",
|
|
|
|
r"f x='abc':",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parameter_default_backtick() {
|
|
|
|
case(
|
|
|
|
r"
|
2019-11-07 10:55:15 -08:00
|
|
|
f x=`echo hello`:
|
2023-11-16 13:51:57 -08:00
|
|
|
",
|
|
|
|
r"f x=`echo hello`:",
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parameter_default_concatenation_string() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
f x=(`echo hello` + "foo"):
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"f x=(`echo hello` + "foo"):"#,
|
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parameter_default_concatenation_variable() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
x := "10"
|
|
|
|
f y=(`echo hello` + x) +z="foo":
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"x := "10"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
f y=(`echo hello` + x) +z="foo":"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn parameter_default_multiple() {
|
|
|
|
case(
|
|
|
|
r#"
|
2019-11-07 10:55:15 -08:00
|
|
|
x := "10"
|
|
|
|
f y=(`echo hello` + x) +z=("foo" + "bar"):
|
|
|
|
"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
r#"x := "10"
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
f y=(`echo hello` + x) +z=("foo" + "bar"):"#,
|
2023-11-16 13:51:57 -08:00
|
|
|
);
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn concatenation_in_group() {
|
|
|
|
case("x := ('0' + '1')", "x := ('0' + '1')");
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn string_in_group() {
|
|
|
|
case("x := ('0' )", "x := ('0')");
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
2023-11-16 13:51:57 -08:00
|
|
|
#[test]
|
|
|
|
fn escaped_dos_newlines() {
|
|
|
|
case("@spam:\r
|
2019-11-07 10:55:15 -08:00
|
|
|
\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; \\
|
2023-11-16 13:51:57 -08:00
|
|
|
} | less");
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|