From d5a5f4256f52ff8967c305c1de21a64641afb983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Hardy?= Date: Thu, 21 Nov 2024 14:32:24 +0100 Subject: [PATCH] Update parser to handle correctly `order-only-prerequisites` 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) --- pkg/parser/parser.go | 2 +- pkg/parser/parser_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index 02d1d13..2df35e6 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -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) diff --git a/pkg/parser/parser_test.go b/pkg/parser/parser_test.go index 8d73a74..149a73f 100644 --- a/pkg/parser/parser_test.go +++ b/pkg/parser/parser_test.go @@ -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}, }