Skip to content

Commit

Permalink
Refactor and rename test macros (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Apr 19, 2019
1 parent d065d1c commit 415c84e
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 260 deletions.
59 changes: 59 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ version = "3.1"
features = ["termination"]

[dev-dependencies]
executable-path = "1.0.0"
executable-path = "1.0.0"
pretty_assertions = "0.6.1"
colored-diff = "0.2.1"
6 changes: 3 additions & 3 deletions src/assignment_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
#[cfg(test)]
mod test {
use super::*;
use crate::testing::parse_success;
use crate::testing::parse;
use brev::OutputError;

fn no_cwd_err() -> Result<PathBuf, String> {
Expand All @@ -174,7 +174,7 @@ mod test {

#[test]
fn backtick_code() {
match parse_success("a:\n echo {{`f() { return 100; }; f`}}")
match parse("a:\n echo {{`f() { return 100; }; f`}}")
.run(&no_cwd_err(), &["a"], &Default::default())
.unwrap_err()
{
Expand Down Expand Up @@ -203,7 +203,7 @@ recipe:
..Default::default()
};

match parse_success(text)
match parse(text)
.run(&no_cwd_err(), &["recipe"], &configuration)
.unwrap_err()
{
Expand Down
8 changes: 4 additions & 4 deletions src/assignment_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'a: 'b, 'b> AssignmentResolver<'a, 'b> {
mod test {
use super::*;

compilation_error_test! {
error_test! {
name: circular_variable_dependency,
input: "a = b\nb = a",
offset: 0,
Expand All @@ -103,7 +103,7 @@ mod test {
kind: CircularVariableDependency{variable: "a", circle: vec!["a", "b", "a"]},
}

compilation_error_test! {
error_test! {
name: self_variable_dependency,
input: "a = a",
offset: 0,
Expand All @@ -113,7 +113,7 @@ mod test {
kind: CircularVariableDependency{variable: "a", circle: vec!["a", "a"]},
}

compilation_error_test! {
error_test! {
name: unknown_expression_variable,
input: "x = yy",
offset: 4,
Expand All @@ -123,7 +123,7 @@ mod test {
kind: UndefinedVariable{variable: "yy"},
}

compilation_error_test! {
error_test! {
name: unknown_function,
input: "a = foo()",
offset: 4,
Expand Down
3 changes: 3 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ pub(crate) use crate::command_ext::CommandExt;

#[allow(unused_imports)]
pub(crate) use crate::range_ext::RangeExt;

#[allow(unused_imports)]
pub(crate) use crate::ordinal::Ordinal;
12 changes: 6 additions & 6 deletions src/compilation_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ impl<'a> Display for CompilationError<'a> {
f,
"Alias `{}` defined on `{}` shadows recipe defined on `{}`",
alias,
self.line + 1,
recipe_line + 1,
self.line.ordinal(),
recipe_line.ordinal(),
)?;
}
CircularRecipeDependency { recipe, ref circle } => {
Expand Down Expand Up @@ -181,8 +181,8 @@ impl<'a> Display for CompilationError<'a> {
f,
"Alias `{}` first defined on line `{}` is redefined on line `{}`",
alias,
first + 1,
self.line + 1,
first.ordinal(),
self.line.ordinal(),
)?;
}
DuplicateDependency { recipe, dependency } => {
Expand All @@ -197,8 +197,8 @@ impl<'a> Display for CompilationError<'a> {
f,
"Recipe `{}` first defined on line {} is redefined on line {}",
recipe,
first + 1,
self.line + 1
first.ordinal(),
self.line.ordinal()
)?;
}
DependencyHasParameters { recipe, dependency } => {
Expand Down
24 changes: 12 additions & 12 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ mod test {
use super::*;

use crate::runtime_error::RuntimeError::*;
use crate::testing::parse_success;
use crate::testing::parse;

fn no_cwd_err() -> Result<PathBuf, String> {
Err(String::from("no cwd in tests"))
}

#[test]
fn unknown_recipes() {
match parse_success("a:\nb:\nc:")
match parse("a:\nb:\nc:")
.run(&no_cwd_err(), &["a", "x", "y", "z"], &Default::default())
.unwrap_err()
{
Expand Down Expand Up @@ -246,7 +246,7 @@ a:
x
";

match parse_success(text)
match parse(text)
.run(&no_cwd_err(), &["a"], &Default::default())
.unwrap_err()
{
Expand All @@ -265,7 +265,7 @@ a:

#[test]
fn code_error() {
match parse_success("fail:\n @exit 100")
match parse("fail:\n @exit 100")
.run(&no_cwd_err(), &["fail"], &Default::default())
.unwrap_err()
{
Expand All @@ -288,7 +288,7 @@ a:
a return code:
@x() { {{return}} {{code + "0"}}; }; x"#;

match parse_success(text)
match parse(text)
.run(&no_cwd_err(), &["a", "return", "15"], &Default::default())
.unwrap_err()
{
Expand All @@ -307,7 +307,7 @@ a return code:

#[test]
fn missing_some_arguments() {
match parse_success("a b c d:")
match parse("a b c d:")
.run(&no_cwd_err(), &["a", "b", "c"], &Default::default())
.unwrap_err()
{
Expand All @@ -331,7 +331,7 @@ a return code:

#[test]
fn missing_some_arguments_variadic() {
match parse_success("a b c +d:")
match parse("a b c +d:")
.run(&no_cwd_err(), &["a", "B", "C"], &Default::default())
.unwrap_err()
{
Expand All @@ -355,7 +355,7 @@ a return code:

#[test]
fn missing_all_arguments() {
match parse_success("a b c d:\n echo {{b}}{{c}}{{d}}")
match parse("a b c d:\n echo {{b}}{{c}}{{d}}")
.run(&no_cwd_err(), &["a"], &Default::default())
.unwrap_err()
{
Expand All @@ -379,7 +379,7 @@ a return code:

#[test]
fn missing_some_defaults() {
match parse_success("a b c d='hello':")
match parse("a b c d='hello':")
.run(&no_cwd_err(), &["a", "b"], &Default::default())
.unwrap_err()
{
Expand All @@ -403,7 +403,7 @@ a return code:

#[test]
fn missing_all_defaults() {
match parse_success("a b c='r' d='h':")
match parse("a b c='r' d='h':")
.run(&no_cwd_err(), &["a"], &Default::default())
.unwrap_err()
{
Expand All @@ -430,7 +430,7 @@ a return code:
let mut configuration: Configuration = Default::default();
configuration.overrides.insert("foo", "bar");
configuration.overrides.insert("baz", "bob");
match parse_success("a:\n echo {{`f() { return 100; }; f`}}")
match parse("a:\n echo {{`f() { return 100; }; f`}}")
.run(&no_cwd_err(), &["a"], &configuration)
.unwrap_err()
{
Expand Down Expand Up @@ -458,7 +458,7 @@ wut:
..Default::default()
};

match parse_success(text)
match parse(text)
.run(&no_cwd_err(), &["wut"], &configuration)
.unwrap_err()
{
Expand Down
Loading

0 comments on commit 415c84e

Please sign in to comment.