@@ -34,6 +34,16 @@ import (
34
34
"github.com/stretchr/testify/require"
35
35
)
36
36
37
+ var projectPaths []string
38
+
39
+ func init () {
40
+ projectPath , err := os .Getwd () // Path to an arbitrary folder that is guaranteed to exist.
41
+ if err != nil {
42
+ panic (err )
43
+ }
44
+ projectPaths = []string {projectPath }
45
+ }
46
+
37
47
func TestInitialize (t * testing.T ) {
38
48
flags := test .ConfigurationFlags ()
39
49
flags .Set ("project-type" , "sketch" )
@@ -52,25 +62,30 @@ func TestInitialize(t *testing.T) {
52
62
}
53
63
54
64
func TestRecord (t * testing.T ) {
65
+ flags := test .ConfigurationFlags ()
66
+ require .Nil (t , configuration .Initialize (flags , projectPaths ))
67
+
55
68
checkedProject := project.Type {
56
69
Path : paths .New ("/foo/bar" ),
57
70
ProjectType : projecttype .Sketch ,
58
71
SuperprojectType : projecttype .Library ,
59
72
}
60
73
61
74
var results Type
75
+ results .Initialize ()
62
76
checkConfiguration := checkconfigurations .Configurations ()[0 ]
63
77
checkOutput := "foo"
64
78
summaryText := results .Record (checkedProject , checkConfiguration , checkresult .Fail , checkOutput )
65
- assert .Equal (t , fmt .Sprintf ("%s \n %s: %s\n " , checkresult .Fail , checklevel .Error , message (checkConfiguration .MessageTemplate , checkOutput )), summaryText )
79
+ assert .Equal (t , fmt .Sprintf ("Check %s result: %s \n %s: %s\n " , checkConfiguration . ID , checkresult .Fail , checklevel .Error , message (checkConfiguration .MessageTemplate , checkOutput )), summaryText )
66
80
summaryText = results .Record (checkedProject , checkConfiguration , checkresult .NotRun , checkOutput )
67
- assert .Equal (t , fmt .Sprintf ("%s \n %s: %s\n " , checkresult .NotRun , checklevel .Notice , checkOutput ), summaryText , "Non-fail result should not use message" )
81
+ assert .Equal (t , fmt .Sprintf ("Check %s result: %s \n %s: %s\n " , checkConfiguration . ID , checkresult .NotRun , checklevel .Notice , checkOutput ), summaryText , "Non-fail result should not use message" )
68
82
summaryText = results .Record (checkedProject , checkConfiguration , checkresult .Pass , "" )
69
83
assert .Equal (t , "" , "" , summaryText , "Non-failure result with no check function output should result in an empty summary" )
70
84
85
+ flags .Set ("verbose" , "true" )
86
+ require .Nil (t , configuration .Initialize (flags , projectPaths ))
71
87
checkResult := checkresult .Pass
72
- results = Type {}
73
-
88
+ results .Initialize ()
74
89
results .Record (checkedProject , checkConfiguration , checkResult , checkOutput )
75
90
projectReport := results .Projects [0 ]
76
91
assert .Equal (t , checkedProject .Path , projectReport .Path )
@@ -80,7 +95,7 @@ func TestRecord(t *testing.T) {
80
95
assert .Equal (t , configuration .CheckModes (checkedProject .ProjectType )[checkmode .LibraryManagerSubmission ], projectConfigurationReport .LibraryManagerSubmit )
81
96
assert .Equal (t , configuration .CheckModes (checkedProject .ProjectType )[checkmode .LibraryManagerIndexed ], projectConfigurationReport .LibraryManagerUpdate )
82
97
assert .Equal (t , configuration .CheckModes (checkedProject .ProjectType )[checkmode .Official ], projectConfigurationReport .Official )
83
-
98
+ assert . Equal ( t , 1 , len ( results . Projects [ 0 ]. Checks ), "Passing check reports should be written to report in verbose mode" )
84
99
checkReport := projectReport .Checks [0 ]
85
100
assert .Equal (t , checkConfiguration .Category , checkReport .Category )
86
101
assert .Equal (t , checkConfiguration .Subcategory , checkReport .Subcategory )
@@ -92,15 +107,25 @@ func TestRecord(t *testing.T) {
92
107
assert .Equal (t , checkLevel .String (), checkReport .Level )
93
108
assert .Equal (t , checkOutput , checkReport .Message )
94
109
110
+ flags .Set ("verbose" , "false" )
111
+ require .Nil (t , configuration .Initialize (flags , projectPaths ))
112
+ results .Initialize ()
113
+ results .Record (checkedProject , checkConfiguration , checkresult .Pass , checkOutput )
114
+ assert .Equal (t , 0 , len (results .Projects [0 ].Checks ), "Passing check reports should not be written to report in non-verbose mode" )
115
+
116
+ results .Initialize ()
117
+ results .Record (checkedProject , checkConfiguration , checkresult .Fail , checkOutput )
118
+ require .Equal (t , 1 , len (projectReport .Checks ), "Failing check reports should be written to report in non-verbose mode" )
119
+
95
120
assert .Len (t , results .Projects , 1 )
96
121
previousProjectPath := checkedProject .Path
97
122
checkedProject .Path = paths .New ("/foo/baz" )
98
- results .Record (checkedProject , checkConfiguration , checkResult , checkOutput )
123
+ results .Record (checkedProject , checkConfiguration , checkresult . Fail , checkOutput )
99
124
assert .Len (t , results .Projects , 2 )
100
125
101
126
assert .Len (t , results .Projects [0 ].Checks , 1 )
102
127
checkedProject .Path = previousProjectPath
103
- results .Record (checkedProject , checkconfigurations .Configurations ()[1 ], checkResult , checkOutput )
128
+ results .Record (checkedProject , checkconfigurations .Configurations ()[1 ], checkresult . Fail , checkOutput )
104
129
assert .Len (t , results .Projects [0 ].Checks , 2 )
105
130
}
106
131
@@ -114,40 +139,61 @@ func TestAddProjectSummary(t *testing.T) {
114
139
testTables := []struct {
115
140
results []checkresult.Type
116
141
levels []checklevel.Type
142
+ verbose string
117
143
expectedPass bool
118
144
expectedWarningCount int
119
145
expectedErrorCount int
120
146
}{
121
147
{
122
148
[]checkresult.Type {checkresult .Pass , checkresult .Pass },
123
149
[]checklevel.Type {checklevel .Info , checklevel .Info },
150
+ "true" ,
151
+ true ,
152
+ 0 ,
153
+ 0 ,
154
+ },
155
+ {
156
+ []checkresult.Type {checkresult .Pass , checkresult .Pass },
157
+ []checklevel.Type {checklevel .Info , checklevel .Info },
158
+ "false" ,
124
159
true ,
125
160
0 ,
126
161
0 ,
127
162
},
128
163
{
129
164
[]checkresult.Type {checkresult .Pass , checkresult .Fail },
130
165
[]checklevel.Type {checklevel .Info , checklevel .Warning },
166
+ "false" ,
131
167
true ,
132
168
1 ,
133
169
0 ,
134
170
},
135
171
{
136
172
[]checkresult.Type {checkresult .Fail , checkresult .Fail },
137
173
[]checklevel.Type {checklevel .Error , checklevel .Warning },
174
+ "false" ,
138
175
false ,
139
176
1 ,
140
177
1 ,
141
178
},
142
179
}
143
180
144
181
for _ , testTable := range testTables {
182
+ flags := test .ConfigurationFlags ()
183
+ flags .Set ("verbose" , testTable .verbose )
184
+ require .Nil (t , configuration .Initialize (flags , projectPaths ))
185
+
145
186
var results Type
146
- for _ , result := range testTable .results {
187
+ results .Initialize ()
188
+
189
+ checkIndex := 0
190
+ for testDataIndex , result := range testTable .results {
147
191
results .Record (checkedProject , checkconfigurations .Configurations ()[0 ], result , "" )
148
- }
149
- for checkIndex , level := range testTable .levels {
150
- results .Projects [0 ].Checks [checkIndex ].Level = level .String ()
192
+ if (result == checkresult .Fail ) || configuration .Verbose () {
193
+ level := testTable .levels [testDataIndex ].String ()
194
+ results .Projects [0 ].Checks [checkIndex ].Level = level
195
+ checkIndex += 1
196
+ }
151
197
}
152
198
results .AddProjectSummary (checkedProject )
153
199
assert .Equal (t , testTable .expectedPass , results .Projects [0 ].Summary .Pass )
@@ -243,10 +289,6 @@ func TestAddSummary(t *testing.T) {
243
289
func TestWriteReport (t * testing.T ) {
244
290
flags := test .ConfigurationFlags ()
245
291
246
- projectPath , err := os .Getwd () // Path to an arbitrary folder that is guaranteed to exist.
247
- require .Nil (t , err )
248
- projectPaths := []string {projectPath }
249
-
250
292
reportFolderPathString , err := ioutil .TempDir ("" , "arduino-check-result-TestWriteReport" )
251
293
require .Nil (t , err )
252
294
defer os .RemoveAll (reportFolderPathString ) // clean up
0 commit comments