aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-08-08 13:06:33 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-08-08 13:07:49 +0200
commitc00da3df66e3212ca3b6ab2a623e9fe5fe6d9e7f (patch)
tree9359ffde3b9ab75a19ef3159e1bd1de7cf31ad17
parent9a791c399266a650acac45ac55a066a84aad7c64 (diff)
prog: collect all prog comments
Parse and collect and prog comments. Will be needed for runtest annotations (e.g. "requires threaded mode", etc).
-rw-r--r--prog/encoding.go14
-rw-r--r--prog/encoding_test.go9
-rw-r--r--prog/prog.go5
3 files changed, 25 insertions, 3 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index bdb00c7cc..92e2c47f0 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -188,10 +188,16 @@ func (target *Target) Deserialize(data []byte) (prog *Prog, err error) {
comment := ""
for p.Scan() {
if p.EOF() {
- comment = ""
+ if comment != "" {
+ prog.Comments = append(prog.Comments, comment)
+ comment = ""
+ }
continue
}
if p.Char() == '#' {
+ if comment != "" {
+ prog.Comments = append(prog.Comments, comment)
+ }
comment = strings.TrimSpace(p.s[p.i+1:])
continue
}
@@ -238,6 +244,9 @@ func (target *Target) Deserialize(data []byte) (prog *Prog, err error) {
if p.Char() != '#' {
return nil, fmt.Errorf("tailing data (line #%v)", p.l)
}
+ if c.Comment != "" {
+ prog.Comments = append(prog.Comments, c.Comment)
+ }
c.Comment = strings.TrimSpace(p.s[p.i+1:])
}
for i := len(c.Args); i < len(meta.Args); i++ {
@@ -251,6 +260,9 @@ func (target *Target) Deserialize(data []byte) (prog *Prog, err error) {
}
comment = ""
}
+ if comment != "" {
+ prog.Comments = append(prog.Comments, comment)
+ }
if err := p.Err(); err != nil {
return nil, err
}
diff --git a/prog/encoding_test.go b/prog/encoding_test.go
index 7ecd811bc..0b3364e63 100644
--- a/prog/encoding_test.go
+++ b/prog/encoding_test.go
@@ -334,4 +334,13 @@ serialize0()
t.Errorf("bad call %v comment: %q, want %q", i, got, want)
}
}
+ wantComments := []string{
+ "comment1",
+ "comment4",
+ "comment6",
+ "comment7",
+ }
+ if !reflect.DeepEqual(p.Comments, wantComments) {
+ t.Errorf("bad program comments %q\nwant: %q", p.Comments, wantComments)
+ }
}
diff --git a/prog/prog.go b/prog/prog.go
index edfbd762c..8d0e0f525 100644
--- a/prog/prog.go
+++ b/prog/prog.go
@@ -8,8 +8,9 @@ import (
)
type Prog struct {
- Target *Target
- Calls []*Call
+ Target *Target
+ Calls []*Call
+ Comments []string
}
type Call struct {