2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) struct AssignmentEvaluator<'a: 'b, 'b> {
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) assignments: &'b BTreeMap<&'a str, Assignment<'a>>,
|
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
|
|
|
pub(crate) config: &'a Config,
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) dotenv: &'b BTreeMap<String, String>,
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) evaluated: BTreeMap<&'a str, (bool, String)>,
|
|
|
|
pub(crate) scope: &'b BTreeMap<&'a str, (bool, String)>,
|
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
|
|
|
pub(crate) working_directory: &'b Path,
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn evaluate_assignments(
|
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: &'a Config,
|
|
|
|
working_directory: &'b Path,
|
2019-04-11 15:23:14 -07:00
|
|
|
dotenv: &'b BTreeMap<String, String>,
|
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
|
|
|
assignments: &BTreeMap<&'a str, Assignment<'a>>,
|
2019-11-07 10:55:15 -08:00
|
|
|
) -> RunResult<'a, BTreeMap<&'a str, (bool, String)>> {
|
2017-11-18 01:18:04 -08:00
|
|
|
let mut evaluator = AssignmentEvaluator {
|
2018-03-05 13:21:35 -08:00
|
|
|
evaluated: empty(),
|
2018-12-08 14:29:41 -08:00
|
|
|
scope: &empty(),
|
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,
|
2018-03-05 13:21:35 -08:00
|
|
|
assignments,
|
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
|
|
|
working_directory,
|
2018-03-05 13:21:35 -08:00
|
|
|
dotenv,
|
2017-11-18 01:18:04 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
for name in assignments.keys() {
|
|
|
|
evaluator.evaluate_assignment(name)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(evaluator.evaluated)
|
|
|
|
}
|
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn evaluate_line(
|
2017-11-16 23:30:08 -08:00
|
|
|
&mut self,
|
2018-12-08 14:29:41 -08:00
|
|
|
line: &[Fragment<'a>],
|
2019-11-07 10:55:15 -08:00
|
|
|
arguments: &BTreeMap<&'a str, Cow<str>>,
|
2017-11-17 17:28:06 -08:00
|
|
|
) -> RunResult<'a, String> {
|
2017-11-16 23:30:08 -08:00
|
|
|
let mut evaluated = String::new();
|
|
|
|
for fragment in line {
|
2019-11-07 10:55:15 -08:00
|
|
|
match fragment {
|
|
|
|
Fragment::Text { token } => evaluated += token.lexeme(),
|
|
|
|
Fragment::Interpolation { expression } => {
|
2017-11-16 23:30:08 -08:00
|
|
|
evaluated += &self.evaluate_expression(expression, arguments)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(evaluated)
|
|
|
|
}
|
|
|
|
|
2017-11-17 17:28:06 -08:00
|
|
|
fn evaluate_assignment(&mut self, name: &'a str) -> RunResult<'a, ()> {
|
2017-11-16 23:30:08 -08:00
|
|
|
if self.evaluated.contains_key(name) {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
if let Some(assignment) = self.assignments.get(name) {
|
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
|
|
|
if let Some(value) = self.config.overrides.get(name) {
|
2019-11-07 10:55:15 -08:00
|
|
|
self
|
|
|
|
.evaluated
|
|
|
|
.insert(name, (assignment.export, value.to_string()));
|
2017-11-16 23:30:08 -08:00
|
|
|
} else {
|
2019-11-07 10:55:15 -08:00
|
|
|
let value = self.evaluate_expression(&assignment.expression, &empty())?;
|
|
|
|
self.evaluated.insert(name, (assignment.export, value));
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err(RuntimeError::Internal {
|
2018-12-08 14:29:41 -08:00
|
|
|
message: format!("attempted to evaluated unknown assignment {}", name),
|
2017-11-16 23:30:08 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn evaluate_expression(
|
2017-11-16 23:30:08 -08:00
|
|
|
&mut self,
|
|
|
|
expression: &Expression<'a>,
|
2019-11-07 10:55:15 -08:00
|
|
|
arguments: &BTreeMap<&'a str, Cow<str>>,
|
2017-11-17 17:28:06 -08:00
|
|
|
) -> RunResult<'a, String> {
|
2019-11-07 10:55:15 -08:00
|
|
|
match expression {
|
2018-12-08 14:29:41 -08:00
|
|
|
Expression::Variable { name, .. } => {
|
2019-11-07 10:55:15 -08:00
|
|
|
let variable = name.lexeme();
|
|
|
|
if self.evaluated.contains_key(variable) {
|
|
|
|
Ok(self.evaluated[variable].1.clone())
|
|
|
|
} else if self.scope.contains_key(variable) {
|
|
|
|
Ok(self.scope[variable].1.clone())
|
|
|
|
} else if self.assignments.contains_key(variable) {
|
|
|
|
self.evaluate_assignment(variable)?;
|
|
|
|
Ok(self.evaluated[variable].1.clone())
|
|
|
|
} else if arguments.contains_key(variable) {
|
|
|
|
Ok(arguments[variable].to_string())
|
2017-11-16 23:30:08 -08:00
|
|
|
} else {
|
2017-12-02 05:37:10 -08:00
|
|
|
Err(RuntimeError::Internal {
|
2019-11-07 10:55:15 -08:00
|
|
|
message: format!("attempted to evaluate undefined variable `{}`", variable),
|
2017-12-02 05:37:10 -08:00
|
|
|
})
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 14:29:41 -08:00
|
|
|
Expression::Call {
|
2019-11-07 10:55:15 -08:00
|
|
|
function,
|
|
|
|
arguments: call_arguments,
|
2018-12-08 14:29:41 -08:00
|
|
|
} => {
|
|
|
|
let call_arguments = call_arguments
|
|
|
|
.iter()
|
|
|
|
.map(|argument| self.evaluate_expression(argument, arguments))
|
|
|
|
.collect::<Result<Vec<String>, RuntimeError>>()?;
|
2018-03-17 09:17:41 -07:00
|
|
|
let context = FunctionContext {
|
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
|
|
|
invocation_directory: &self.config.invocation_directory,
|
|
|
|
working_directory: &self.working_directory,
|
2018-03-17 09:17:41 -07:00
|
|
|
dotenv: self.dotenv,
|
|
|
|
};
|
2019-11-07 10:55:15 -08:00
|
|
|
Function::evaluate(*function, &context, &call_arguments)
|
2017-12-02 14:59:07 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
Expression::StringLiteral { string_literal } => Ok(string_literal.cooked.to_string()),
|
|
|
|
Expression::Backtick { contents, token } => {
|
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
|
|
|
if self.config.dry_run {
|
2019-11-07 10:55:15 -08:00
|
|
|
Ok(format!("`{}`", contents))
|
2017-11-17 20:21:37 -08:00
|
|
|
} else {
|
2019-11-07 10:55:15 -08:00
|
|
|
Ok(self.run_backtick(self.dotenv, contents, token)?)
|
2017-11-17 20:21:37 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
Expression::Concatination { lhs, rhs } => {
|
2018-12-08 14:29:41 -08:00
|
|
|
Ok(self.evaluate_expression(lhs, arguments)? + &self.evaluate_expression(rhs, arguments)?)
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
Expression::Group { contents } => self.evaluate_expression(contents, arguments),
|
2017-12-02 05:37:10 -08:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2017-11-17 20:21:37 -08:00
|
|
|
|
|
|
|
fn run_backtick(
|
|
|
|
&self,
|
2019-04-11 15:23:14 -07:00
|
|
|
dotenv: &BTreeMap<String, String>,
|
2018-12-08 14:29:41 -08:00
|
|
|
raw: &str,
|
|
|
|
token: &Token<'a>,
|
2017-11-17 20:21:37 -08:00
|
|
|
) -> RunResult<'a, String> {
|
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 mut cmd = Command::new(&self.config.shell);
|
|
|
|
|
|
|
|
cmd.current_dir(self.working_directory);
|
2017-11-17 20:21:37 -08:00
|
|
|
|
2019-04-16 19:52:16 -07:00
|
|
|
cmd.arg("-cu").arg(raw);
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
cmd.export_environment_variables(self.scope, dotenv)?;
|
2017-11-17 20:21:37 -08:00
|
|
|
|
2019-04-16 19:52:16 -07:00
|
|
|
cmd.stdin(process::Stdio::inherit());
|
2017-11-17 20:21:37 -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
|
|
|
cmd.stderr(if self.config.quiet {
|
2017-11-17 20:21:37 -08:00
|
|
|
process::Stdio::null()
|
|
|
|
} else {
|
|
|
|
process::Stdio::inherit()
|
|
|
|
});
|
|
|
|
|
2018-12-08 14:29:41 -08:00
|
|
|
InterruptHandler::guard(|| {
|
2019-07-13 01:55:06 -07:00
|
|
|
output(cmd).map_err(|output_error| RuntimeError::Backtick {
|
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
|
|
|
token: *token,
|
2018-12-08 14:29:41 -08:00
|
|
|
output_error,
|
|
|
|
})
|
|
|
|
})
|
2017-11-17 20:21:37 -08:00
|
|
|
}
|
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::*;
|
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
|
|
|
use crate::testing::{compile, config};
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2017-11-17 17:28:06 -08:00
|
|
|
#[test]
|
|
|
|
fn backtick_code() {
|
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 justfile = compile("a:\n echo {{`f() { return 100; }; f`}}");
|
|
|
|
let config = config(&["a"]);
|
|
|
|
let dir = env::current_dir().unwrap();
|
|
|
|
match justfile.run(&config, &dir).unwrap_err() {
|
2018-12-08 14:29:41 -08:00
|
|
|
RuntimeError::Backtick {
|
|
|
|
token,
|
|
|
|
output_error: OutputError::Code(code),
|
|
|
|
} => {
|
2017-11-17 17:28:06 -08:00
|
|
|
assert_eq!(code, 100);
|
2019-04-15 22:40:02 -07:00
|
|
|
assert_eq!(token.lexeme(), "`f() { return 100; }; f`");
|
2018-12-08 14:29:41 -08:00
|
|
|
}
|
2017-11-17 17:28:06 -08:00
|
|
|
other => panic!("expected a code run error, but got: {}", other),
|
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2017-11-17 17:28:06 -08:00
|
|
|
#[test]
|
|
|
|
fn export_assignment_backtick() {
|
|
|
|
let text = r#"
|
2017-11-16 23:30:08 -08:00
|
|
|
export exported_variable = "A"
|
|
|
|
b = `echo $exported_variable`
|
|
|
|
|
|
|
|
recipe:
|
|
|
|
echo {{b}}
|
|
|
|
"#;
|
2017-11-17 17:28:06 -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 justfile = compile(text);
|
|
|
|
let config = config(&["--quiet", "recipe"]);
|
|
|
|
let dir = env::current_dir().unwrap();
|
|
|
|
|
|
|
|
match justfile.run(&config, &dir).unwrap_err() {
|
2018-12-08 14:29:41 -08:00
|
|
|
RuntimeError::Backtick {
|
|
|
|
token,
|
|
|
|
output_error: OutputError::Code(_),
|
|
|
|
} => {
|
2019-04-15 22:40:02 -07:00
|
|
|
assert_eq!(token.lexeme(), "`echo $exported_variable`");
|
2018-12-08 14:29:41 -08:00
|
|
|
}
|
2017-11-17 17:28:06 -08:00
|
|
|
other => panic!("expected a backtick code errror, but got: {}", other),
|
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|