@@ -26,8 +26,8 @@ import (
2626)
2727
2828var (
29- passCaseExt = regexp .MustCompile (`\w:pattern-test-pass` )
30- failCaseExt = regexp .MustCompile (`\w:pattern-test-fail` )
29+ passCaseExt = regexp .MustCompile (`\w+ :pattern-test-pass` )
30+ failCaseExt = regexp .MustCompile (`\w+ :pattern-test-fail` )
3131)
3232
3333// YANGLeaf is a structure used to describe a particular leaf of YANG schema.
@@ -45,39 +45,42 @@ type RegexpTest struct {
4545// CheckRegexps tests mock input data against a set of leaves that have pattern
4646// test cases specified for them. It ensures that the regexp compiles as a
4747// POSIX regular expression according to the OpenConfig style guide.
48- func CheckRegexps (yangfiles , paths []string ) error {
48+ func CheckRegexps (yangfiles , paths []string ) ([] string , error ) {
4949 yangE , errs := yangutil .ProcessModules (yangfiles , paths )
5050 if len (errs ) != 0 {
51- return fmt .Errorf ("could not parse modules: %v" , errs )
51+ return nil , fmt .Errorf ("could not parse modules: %v" , errs )
5252 }
5353 if len (yangE ) == 0 {
54- return fmt .Errorf ("did not parse any modules" )
54+ return nil , fmt .Errorf ("did not parse any modules" )
5555 }
5656
57- var errs2 util.Errors
57+ var patternErrs util.Errors
58+ var allFailMessages []string
5859 for _ , mod := range yangE {
5960 for _ , entry := range mod .Dir {
60- if err := checkEntryPatterns (entry ); err != nil {
61- errs2 = util .AppendErr (errs2 , err )
61+ if failMessages , err := checkEntryPatterns (entry ); err != nil {
62+ patternErrs = util .AppendErr (patternErrs , err )
63+ } else {
64+ allFailMessages = append (allFailMessages , failMessages ... )
6265 }
6366 }
6467 }
65- if len (errs2 ) = = 0 {
66- return nil
68+ if len (patternErrs ) ! = 0 {
69+ return nil , patternErrs
6770 }
68- return errs2
71+ return allFailMessages , nil
6972}
7073
71- func checkEntryPatterns (entry * yang.Entry ) error {
74+ func checkEntryPatterns (entry * yang.Entry ) ([] string , error ) {
7275 if entry .Kind != yang .LeafEntry {
73- return nil
76+ return nil , nil
7477 }
7578
7679 if len (entry .Errors ) != 0 {
77- return fmt .Errorf ("entry had associated errors: %v" , entry .Errors )
80+ return nil , fmt .Errorf ("entry had associated errors: %v" , entry .Errors )
7881 }
7982
80- var errs util. Errors
83+ var failMessages [] string
8184 for _ , ext := range entry .Exts {
8285 var wantMatch bool
8386 switch {
@@ -93,7 +96,7 @@ func checkEntryPatterns(entry *yang.Entry) error {
9396 if len (entry .Type .Type ) == 0 {
9497 var err error
9598 if gotMatch , err = checkPatterns (ext .Argument , entry .Type .POSIXPattern ); err != nil {
96- return err
99+ return nil , err
97100 }
98101 } else {
99102 // Handle unions.
@@ -107,26 +110,23 @@ func checkEntryPatterns(entry *yang.Entry) error {
107110 }
108111 matches , err := checkPatterns (ext .Argument , membertype .POSIXPattern )
109112 if err != nil {
110- return err
113+ return nil , err
111114 }
112115 gotMatch = gotMatch || matches
113116 }
114117 }
115118
116- matchDesc := fmt .Sprintf ("%q doesn't match type %s (leaf %s) " , ext . Argument , entry .Type .Name , entry . Name )
117- if gotMatch {
118- matchDesc = fmt .Sprintf ("%q matches type %s (leaf %s) " , ext . Argument , entry .Type .Name , entry . Name )
119+ matchDesc := fmt .Sprintf ("| `%s` | `%s` | `%s` matched but shouldn't | " , entry . Name , entry .Type .Name , ext . Argument )
120+ if ! gotMatch {
121+ matchDesc = fmt .Sprintf ("| `%s` | `%s` | `%s` did not match | " , entry . Name , entry .Type .Name , ext . Argument )
119122 }
120123
121124 if gotMatch != wantMatch {
122- errs = util . AppendErr ( errs , fmt . Errorf ( "fail: %s" , matchDesc ) )
125+ failMessages = append ( failMessages , matchDesc )
123126 }
124127 log .Infof ("pass: %s" , matchDesc )
125128 }
126- if len (errs ) == 0 {
127- return nil
128- }
129- return errs
129+ return failMessages , nil
130130}
131131
132132// checkPatterns compiles all given POSIX patterns, and returns true if
0 commit comments