Skip to content

Commit 12c0dbc

Browse files
committed
Refactor project identification functions
Consolidate the redundant logging code in these functions.
1 parent 100b2dd commit 12c0dbc

File tree

4 files changed

+64
-20
lines changed

4 files changed

+64
-20
lines changed

configuration/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Initialize() {
3131
//reportFilePath = paths.New("report.json")
3232

3333
feedback.SetFormat(feedback.JSON)
34-
logrus.SetLevel(logrus.PanicLevel)
34+
logrus.SetLevel(logrus.TraceLevel)
3535

3636
logrus.WithFields(logrus.Fields{
3737
"superproject type filter": SuperprojectTypeFilter(),

project/project.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,40 +143,46 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
143143
// isProject determines if a path contains an Arduino project, and if so which type.
144144
func isProject(potentialProjectPath *paths.Path, projectTypeFilter projecttype.Type) (bool, projecttype.Type) {
145145
logrus.Tracef("Checking if %s is %s", potentialProjectPath, projectTypeFilter)
146+
147+
projectType := projecttype.Not
146148
if projectTypeFilter.Matches(projecttype.Sketch) && isSketch(potentialProjectPath) {
147-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Sketch)
148-
return true, projecttype.Sketch
149+
projectType = projecttype.Sketch
149150
} else if projectTypeFilter.Matches(projecttype.Library) && isLibrary(potentialProjectPath) {
150-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Library)
151-
return true, projecttype.Library
151+
projectType = projecttype.Library
152152
} else if projectTypeFilter.Matches(projecttype.Platform) && isPlatform(potentialProjectPath) {
153-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Platform)
154-
return true, projecttype.Platform
153+
projectType = projecttype.Platform
155154
} else if projectTypeFilter.Matches(projecttype.PackageIndex) && isPackageIndex(potentialProjectPath) {
156-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.PackageIndex)
157-
return true, projecttype.PackageIndex
155+
projectType = projecttype.PackageIndex
156+
}
157+
158+
if projectType == projecttype.Not {
159+
return false, projectType
158160
}
159-
return false, projecttype.Not
161+
logrus.Tracef("%s is %s", potentialProjectPath, projectType)
162+
return true, projectType
160163
}
161164

162165
// isProject determines if a file is the indicator file for an Arduino project, and if so which type.
163166
func isProjectIndicatorFile(potentialProjectFilePath *paths.Path, projectTypeFilter projecttype.Type) (bool, projecttype.Type) {
164167
logrus.Tracef("Checking if %s is %s indicator file", potentialProjectFilePath, projectTypeFilter)
168+
169+
projectType := projecttype.Not
165170
if projectTypeFilter.Matches(projecttype.Sketch) && isSketchIndicatorFile(potentialProjectFilePath) {
166-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Sketch)
167-
return true, projecttype.Sketch
171+
projectType = projecttype.Sketch
168172
} else if projectTypeFilter.Matches(projecttype.Library) && isLibraryIndicatorFile(potentialProjectFilePath) {
169-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Library)
170-
return true, projecttype.Library
173+
projectType = projecttype.Library
171174
} else if projectTypeFilter.Matches(projecttype.Platform) && isPlatformIndicatorFile(potentialProjectFilePath) {
172-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Platform)
173-
return true, projecttype.Platform
175+
projectType = projecttype.Platform
174176
} else if projectTypeFilter.Matches(projecttype.PackageIndex) && isPackageIndexIndicatorFile(potentialProjectFilePath) {
175-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.PackageIndex)
176-
return true, projecttype.PackageIndex
177+
projectType = projecttype.PackageIndex
178+
}
179+
180+
if projectType == projecttype.Not {
181+
logrus.Tracef("%s is not indicator file", potentialProjectFilePath)
182+
return false, projectType
177183
}
178-
logrus.Tracef("%s is not indicator file", potentialProjectFilePath)
179-
return false, projecttype.Not
184+
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projectType)
185+
return true, projectType
180186
}
181187

182188
// isSketch determines whether a path is an Arduino sketch.

project/project_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Package project finds and classifies Arduino projects.
2+
package project
3+
4+
import (
5+
"fmt"
6+
"testing"
7+
8+
"github.com/arduino/arduino-check/project/projecttype"
9+
"github.com/arduino/go-paths-helper"
10+
"github.com/sirupsen/logrus"
11+
)
12+
13+
func Test_isProject(t *testing.T) {
14+
somepath := paths.New("e:/deleteme")
15+
fmt.Printf("%s-%s", somepath, projecttype.Sketch)
16+
17+
logrus.SetLevel(logrus.DebugLevel)
18+
logrus.WithFields(logrus.Fields{
19+
"superproject type filter": projecttype.Sketch,
20+
"recursive": true,
21+
"projects path": somepath,
22+
}).Debug("Configuration initialized")
23+
24+
}

result/result_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Package result records check results and provides reports and summary text on those results.
2+
package result
3+
4+
import (
5+
"fmt"
6+
"testing"
7+
8+
"github.com/arduino/arduino-check/check/checkresult"
9+
)
10+
11+
func TestInitialize(t *testing.T) {
12+
summaryText := fmt.Sprintf("%v\n", checkresult.Fail)
13+
print(summaryText)
14+
}

0 commit comments

Comments
 (0)