|
| 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 checkdata |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/arduino/arduino-check/project" |
| 22 | + "github.com/arduino/arduino-check/project/projecttype" |
| 23 | + "github.com/arduino/go-paths-helper" |
| 24 | + "github.com/stretchr/testify/assert" |
| 25 | +) |
| 26 | + |
| 27 | +var platformTestDataPath *paths.Path |
| 28 | + |
| 29 | +func init() { |
| 30 | + workingDirectory, err := paths.Getwd() |
| 31 | + if err != nil { |
| 32 | + panic(err) |
| 33 | + } |
| 34 | + platformTestDataPath = workingDirectory.Join("testdata", "platforms") |
| 35 | +} |
| 36 | + |
| 37 | +func TestInitializeForPlatform(t *testing.T) { |
| 38 | + testTables := []struct { |
| 39 | + testName string |
| 40 | + platformFolderName string |
| 41 | + boardsTxtAssertion assert.ValueAssertionFunc |
| 42 | + boardsTxtLoadErrorAssertion assert.ValueAssertionFunc |
| 43 | + }{ |
| 44 | + {"Valid", "valid-boards.txt", assert.NotNil, assert.Nil}, |
| 45 | + {"Invalid", "invalid-boards.txt", assert.Nil, assert.NotNil}, |
| 46 | + {"Missing", "missing-boards.txt", assert.NotNil, assert.Nil}, |
| 47 | + } |
| 48 | + |
| 49 | + for _, testTable := range testTables { |
| 50 | + |
| 51 | + testProject := project.Type{ |
| 52 | + Path: platformTestDataPath.Join(testTable.platformFolderName), |
| 53 | + ProjectType: projecttype.Platform, |
| 54 | + SuperprojectType: projecttype.Platform, |
| 55 | + } |
| 56 | + Initialize(testProject, nil) |
| 57 | + |
| 58 | + testTable.boardsTxtLoadErrorAssertion(t, BoardsTxtLoadError(), testTable.testName) |
| 59 | + if BoardsTxtLoadError() == nil { |
| 60 | + testTable.boardsTxtAssertion(t, BoardsTxt(), testTable.testName) |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments