diff --git a/fixtures/forwardslash-comments.Procfile b/fixtures/forwardslash-comments.Procfile new file mode 100644 index 0000000..29db747 --- /dev/null +++ b/fixtures/forwardslash-comments.Procfile @@ -0,0 +1,5 @@ +// ignore this +web: python web.py +# this too +worker: node worker.js # testing inline comment +worker-2: node worker.js // testing inline forwardslash comment \ No newline at end of file diff --git a/procfile/parse.go b/procfile/parse.go index 72f8c15..5f8900b 100644 --- a/procfile/parse.go +++ b/procfile/parse.go @@ -38,6 +38,7 @@ func ParseProcfile(text string, delimiter string, strict bool) ([]ProcfileEntry, reOldCmd, _ := regexp.Compile(`^([A-Za-z0-9_-]+)` + delimiter + `\s*(.+)$`) reComment, _ := regexp.Compile(`^(.*)\s#.+$`) + reForwardslashComment, _ := regexp.Compile(`^(.*)\s//.+$`) lineNumber := 0 names := make(map[string]bool) @@ -55,7 +56,7 @@ func ParseProcfile(text string, delimiter string, strict bool) ([]ProcfileEntry, params := reCmd.FindStringSubmatch(line) isCommand := len(params) == 4 isOldCommand := len(oldParams) == 3 - isComment := strings.HasPrefix(line, "#") + isComment := strings.HasPrefix(line, "#") || strings.HasPrefix(line, "//") if isComment { continue } @@ -88,12 +89,15 @@ func ParseProcfile(text string, delimiter string, strict bool) ([]ProcfileEntry, names[name] = true commentParams := reComment.FindStringSubmatch(cmd) + reForwardslashCommentParams := reForwardslashComment.FindStringSubmatch(cmd) if len(commentParams) == 2 { cmd = commentParams[1] + } else if len(reForwardslashCommentParams) == 2 { + cmd = reForwardslashCommentParams[1] } cmd = strings.TrimSpace(cmd) - if strings.HasPrefix(cmd, "#") { + if strings.HasPrefix(cmd, "#") || strings.HasPrefix(cmd, "//") { return entries, fmt.Errorf("comment specified in place of command, line %d", lineNumber) } diff --git a/test.bats b/test.bats index 1ec20d4..81edc96 100644 --- a/test.bats +++ b/test.bats @@ -19,6 +19,20 @@ teardown_file() { assert_output_contains "valid procfile detected 2custom, cron, custom, release, web, wor-ker" } +@test "[lax] forwardslash-comments" { + run $PROCFILE_BIN check -P fixtures/forwardslash-comments.Procfile + echo "output: $output" + echo "status: $status" + [[ "$status" -eq 0 ]] + assert_output_contains "valid procfile detected web, worker, worker-2" + + run $PROCFILE_BIN show -P fixtures/forwardslash-comments.Procfile -p worker + echo "output: $output" + echo "status: $status" + [[ "$status" -eq 0 ]] + assert_output_contains "node worker.js" +} + @test "[lax] multiple" { run $PROCFILE_BIN check -P fixtures/multiple.Procfile echo "output: $output" @@ -49,6 +63,20 @@ teardown_file() { assert_output_contains "valid procfile detected 2custom, cron, custom, release, web, wor-ker" } +@test "[strict] forwardslash-comments" { + run $PROCFILE_BIN check -S -P fixtures/forwardslash-comments.Procfile + echo "output: $output" + echo "status: $status" + [[ "$status" -eq 0 ]] + assert_output_contains "valid procfile detected web, worker, worker-2" + + run $PROCFILE_BIN show -S -P fixtures/forwardslash-comments.Procfile -p worker + echo "output: $output" + echo "status: $status" + [[ "$status" -eq 0 ]] + assert_output_contains "node worker.js" +} + @test "[strict] multiple" { run $PROCFILE_BIN check -S -P fixtures/multiple.Procfile echo "output: $output"