Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,19 +854,25 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
let mut attributes = BTreeMap::new();

while self.accepted(BracketL)? {
let name = self.parse_name()?;
let attribute = Attribute::from_name(name).ok_or_else(|| {
name.error(CompileErrorKind::UnknownAttribute {
attribute: name.lexeme(),
})
})?;
if let Some(line) = attributes.get(&attribute) {
return Err(name.error(CompileErrorKind::DuplicateAttribute {
attribute: name.lexeme(),
first: *line,
}));
loop {
let name = self.parse_name()?;
let attribute = Attribute::from_name(name).ok_or_else(|| {
name.error(CompileErrorKind::UnknownAttribute {
attribute: name.lexeme(),
})
})?;
if let Some(line) = attributes.get(&attribute) {
return Err(name.error(CompileErrorKind::DuplicateAttribute {
attribute: name.lexeme(),
first: *line,
}));
}
attributes.insert(attribute, name.line);

if !self.accepted(TokenKind::Comma)? {
break;
}
}
attributes.insert(attribute, name.line);
self.expect(BracketR)?;
self.expect_eol()?;
}
Expand Down
62 changes: 62 additions & 0 deletions tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}