|
| 1 | +// This file is part of arduino-check. |
| 2 | +// |
| 3 | +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-check. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +package checkfunctions |
| 17 | + |
| 18 | +import ( |
| 19 | + "os" |
| 20 | + "regexp" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/arduino/arduino-check/check/checkdata" |
| 24 | + "github.com/arduino/arduino-check/check/checkresult" |
| 25 | + "github.com/arduino/arduino-check/project" |
| 26 | + "github.com/arduino/arduino-check/project/projecttype" |
| 27 | + "github.com/arduino/go-paths-helper" |
| 28 | + "github.com/stretchr/testify/assert" |
| 29 | +) |
| 30 | + |
| 31 | +var sketchesTestDataPath *paths.Path |
| 32 | + |
| 33 | +func init() { |
| 34 | + workingDirectory, _ := os.Getwd() |
| 35 | + sketchesTestDataPath = paths.New(workingDirectory, "testdata", "sketches") |
| 36 | +} |
| 37 | + |
| 38 | +type sketchCheckFunctionTestTable struct { |
| 39 | + testName string |
| 40 | + sketchFolderName string |
| 41 | + expectedCheckResult checkresult.Type |
| 42 | + expectedOutputQuery string |
| 43 | +} |
| 44 | + |
| 45 | +func checkSketchCheckFunction(checkFunction Type, testTables []sketchCheckFunctionTestTable, t *testing.T) { |
| 46 | + for _, testTable := range testTables { |
| 47 | + expectedOutputRegexp := regexp.MustCompile(testTable.expectedOutputQuery) |
| 48 | + |
| 49 | + testProject := project.Type{ |
| 50 | + Path: sketchesTestDataPath.Join(testTable.sketchFolderName), |
| 51 | + ProjectType: projecttype.Sketch, |
| 52 | + SuperprojectType: projecttype.Sketch, |
| 53 | + } |
| 54 | + |
| 55 | + checkdata.Initialize(testProject, schemasPath) |
| 56 | + |
| 57 | + result, output := checkFunction() |
| 58 | + assert.Equal(t, testTable.expectedCheckResult, result, testTable.testName) |
| 59 | + assert.True(t, expectedOutputRegexp.MatchString(output), testTable.testName) |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +func TestProhibitedCharactersInSketchFileName(t *testing.T) { |
| 64 | + testTables := []sketchCheckFunctionTestTable{ |
| 65 | + {"Has prohibited characters", "ProhibitedCharactersInFileName", checkresult.Fail, "^Prohibited CharactersInFileName.h$"}, |
| 66 | + {"No prohibited characters", "Valid", checkresult.Pass, ""}, |
| 67 | + } |
| 68 | + |
| 69 | + checkSketchCheckFunction(ProhibitedCharactersInSketchFileName, testTables, t) |
| 70 | +} |
0 commit comments