|
| 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 testDataPath *paths.Path |
| 32 | + |
| 33 | +func init() { |
| 34 | + workingDirectory, _ := os.Getwd() |
| 35 | + testDataPath = paths.New(workingDirectory, "testdata", "general") |
| 36 | +} |
| 37 | + |
| 38 | +type checkFunctionTestTable struct { |
| 39 | + testName string |
| 40 | + projectFolderName string |
| 41 | + projectType projecttype.Type |
| 42 | + superProjectType projecttype.Type |
| 43 | + expectedCheckResult checkresult.Type |
| 44 | + expectedOutputQuery string |
| 45 | +} |
| 46 | + |
| 47 | +func checkCheckFunction(checkFunction Type, testTables []checkFunctionTestTable, t *testing.T) { |
| 48 | + for _, testTable := range testTables { |
| 49 | + expectedOutputRegexp := regexp.MustCompile(testTable.expectedOutputQuery) |
| 50 | + |
| 51 | + testProject := project.Type{ |
| 52 | + Path: testDataPath.Join(testTable.projectFolderName), |
| 53 | + ProjectType: testTable.projectType, |
| 54 | + SuperprojectType: testTable.superProjectType, |
| 55 | + } |
| 56 | + |
| 57 | + checkdata.Initialize(testProject, schemasPath) |
| 58 | + |
| 59 | + result, output := checkFunction() |
| 60 | + assert.Equal(t, testTable.expectedCheckResult, result, testTable.testName) |
| 61 | + assert.True(t, expectedOutputRegexp.MatchString(output), testTable.testName) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +func TestMissingReadme(t *testing.T) { |
| 66 | + testTables := []checkFunctionTestTable{ |
| 67 | + {"Readme", "readme", projecttype.Sketch, projecttype.Sketch, checkresult.Pass, ""}, |
| 68 | + {"No readme", "no-readme", projecttype.Sketch, projecttype.Sketch, checkresult.Fail, ""}, |
| 69 | + } |
| 70 | + |
| 71 | + checkCheckFunction(MissingReadme, testTables, t) |
| 72 | +} |
0 commit comments