Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaddeo committed Feb 1, 2025
1 parent ddfcd5f commit 17c3ca8
Showing 1 changed file with 150 additions and 0 deletions.
150 changes: 150 additions & 0 deletions tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,153 @@ fn aliases_can_be_defined_as_attributes() {
.status(EXIT_SUCCESS)
.run();
}

#[test]
fn multiple_aliases_can_be_defined_as_attributes() {
Test::new()
.justfile(
"
[alias('bar')]
[alias('foo')]
baz:
",
)
.arg("foo")
.status(EXIT_SUCCESS)
.run();
}

#[test]
fn duplicate_alias_attributes_are_forbidden() {
Test::new()
.justfile(
"
[alias('foo')]
[alias('foo')]
baz:
",
)
.arg("foo")
.stderr(
"
error: Alias `foo` first defined on line 1 is redefined on line 2
β€”β€”β–Ά justfile:2:9
β”‚
2 β”‚ [alias('foo')]
β”‚ ^^^
",
)
.status(EXIT_FAILURE)
.run();
}

#[test]
fn alias_attributes_duplicating_alias_definition_is_forbidden() {
Test::new()
.justfile(
"
alias foo := baz
[alias('foo')]
baz:
",
)
.arg("foo")
.stderr(
"
error: Alias `foo` first defined on line 1 is redefined on line 2
β€”β€”β–Ά justfile:2:9
β”‚
2 β”‚ [alias('foo')]
β”‚ ^^^
",
)
.status(EXIT_FAILURE)
.run();
}

#[test]
fn alias_definitions_duplicating_alias_attributes_is_forbidden() {
Test::new()
.justfile(
"
[alias('foo')]
baz:
alias foo := baz
",
)
.arg("foo")
.stderr(
"
error: Alias `foo` first defined on line 1 is redefined on line 4
β€”β€”β–Ά justfile:4:7
β”‚
4 β”‚ alias foo := baz
β”‚ ^^^
",
)
.status(EXIT_FAILURE)
.run();
}

#[test]
fn alphanumeric_and_underscores_are_valid_alias_attributes() {
let out = Test::new()
.justfile(
"
[alias('alpha_numeric_123')]
baz:
",
)
.arg("alpha_numeric_123")
.status(EXIT_SUCCESS)
.run();

dbg!(out.stdout);
}

#[test]
fn nonalphanumeric_alias_attribute_is_forbidden() {
Test::new()
.justfile(
"
[alias('invalid name!')]
baz:
",
)
.arg("foo")
.stderr(
"
error: `invalid name!` is not a valid alias. Aliases must only contain alphanumeric characters and underscores.
β€”β€”β–Ά justfile:1:9
β”‚
1 β”‚ [alias('invalid name!')]
β”‚ ^^^^^^^^^^^^^
",
)
.status(EXIT_FAILURE)
.run();
}

#[test]
fn empty_alias_attribute_is_forbidden() {
Test::new()
.justfile(
"
[alias('')]
baz:
",
)
.arg("baz")
.stderr(
"
error: `` is not a valid alias. Aliases must only contain alphanumeric characters and underscores.
β€”β€”β–Ά justfile:1:9
β”‚
1 β”‚ [alias('')]
β”‚ ^
",
)
.status(EXIT_FAILURE)
.run();
}

0 comments on commit 17c3ca8

Please sign in to comment.