|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2019 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-cli. |
| 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 modify or |
| 12 | +// otherwise use the software for commercial activities involving the Arduino |
| 13 | +// software without disclosing the source code of your own applications. To purchase |
| 14 | +// a commercial license, send an email to license@arduino.cc. |
| 15 | + |
| 16 | +package builder_test |
| 17 | + |
| 18 | +import ( |
| 19 | + "io/ioutil" |
| 20 | + "os" |
| 21 | + "path/filepath" |
| 22 | + "testing" |
| 23 | + |
| 24 | + "github.com/arduino/arduino-cli/arduino/builder" |
| 25 | + "github.com/stretchr/testify/assert" |
| 26 | +) |
| 27 | + |
| 28 | +func TestSaveSketch(t *testing.T) { |
| 29 | + sketchName := t.Name() + ".ino" |
| 30 | + outName := sketchName + ".cpp" |
| 31 | + sketchFile := filepath.Join("testdata", sketchName) |
| 32 | + tmp := tmpDirOrDie() |
| 33 | + defer os.RemoveAll(tmp) |
| 34 | + source, err := ioutil.ReadFile(sketchFile) |
| 35 | + if err != nil { |
| 36 | + t.Fatalf("unable to read golden file %s: %v", sketchFile, err) |
| 37 | + } |
| 38 | + |
| 39 | + builder.SaveSketch(sketchName, string(source), tmp) |
| 40 | + |
| 41 | + out, err := ioutil.ReadFile(filepath.Join(tmp, outName)) |
| 42 | + if err != nil { |
| 43 | + t.Fatalf("unable to read output file %s: %v", outName, err) |
| 44 | + } |
| 45 | + |
| 46 | + assert.Equal(t, source, out) |
| 47 | +} |
0 commit comments