Skip to content

Commit

Permalink
Update parser to handle correctly order-only-prerequisites
Browse files Browse the repository at this point in the history
Without this commit, a node without name is generated in `graph.svg` when a `|` (aka pipe) is in prerequisites.

(see https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html)
  • Loading branch information
fhardy-norsys committed Nov 21, 2024
1 parent e54d21c commit d5a5f42
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (p *Parser) parseVertices(g graph.Graph[string], line string) error {

for _, v := range strings.Split(toItems, " ") {
v = strings.TrimSpace(v)
if v == "" {
if v == "" || v == "|" {
continue
}
g.AddVertex(v)
Expand Down
3 changes: 3 additions & 0 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func TestParseVerticesLine(t *testing.T) {
testCases := []testCase{
{line: "foo:", wantErr: nil, wantVs: 1, wantEs: 0},
{line: "foo: bar", wantErr: nil, wantVs: 2, wantEs: 1},
{line: "foo: | bar", wantErr: nil, wantVs: 2, wantEs: 1},
{line: "foo: bar | baz", wantErr: nil, wantVs: 3, wantEs: 2},
{line: "foo: baz qux", wantErr: nil, wantVs: 3, wantEs: 2},
{line: "foo bar: baz qux", wantErr: nil, wantVs: 4, wantEs: 4},
{line: "foo", wantErr: ErrInvalidTarget},
}
Expand Down

0 comments on commit d5a5f42

Please sign in to comment.