Allow multiple attributes on one line (#1537)

This commit is contained in:
Greg Shuflin 2023-01-26 23:54:24 -08:00 committed by GitHub
parent 054d6672c5
commit 687831816d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 12 deletions

View File

@ -854,6 +854,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
let mut attributes = BTreeMap::new();
while self.accepted(BracketL)? {
loop {
let name = self.parse_name()?;
let attribute = Attribute::from_name(name).ok_or_else(|| {
name.error(CompileErrorKind::UnknownAttribute {
@ -867,6 +868,11 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
}));
}
attributes.insert(attribute, name.line);
if !self.accepted(TokenKind::Comma)? {
break;
}
}
self.expect(BracketR)?;
self.expect_eol()?;
}

View File

@ -41,3 +41,65 @@ fn duplicate_attributes_are_disallowed() {
.status(1)
.run();
}
#[test]
fn multiple_attributes_one_line() {
Test::new()
.justfile(
"
[macos, windows,linux]
[no-exit-message]
foo:
exit 1
",
)
.stderr("exit 1\n")
.status(1)
.run();
}
#[test]
fn multiple_attributes_one_line_error_message() {
Test::new()
.justfile(
"
[macos, windows linux]
[no-exit-message]
foo:
exit 1
",
)
.stderr(
"
error: Expected ']' or ',', but found identifier
|
1 | [macos, windows linux]
| ^^^^^
",
)
.status(1)
.run();
}
#[test]
fn multiple_attributes_one_line_duplicate_check() {
Test::new()
.justfile(
"
[macos, windows, linux]
[linux]
foo:
exit 1
",
)
.stderr(
"
error: Recipe attribute `linux` first used on line 1 is duplicated on line 2
|
2 | [linux]
| ^^^^^
",
)
.status(1)
.run();
}