Skip to content

Commit a22edfa

Browse files
committed
Added unit tests for compilation_database
1 parent cf8fd8f commit a22edfa

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Diff for: arduino/builder/compilation_database_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of arduino-cli.
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-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
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 builder
17+
18+
import (
19+
"os/exec"
20+
"testing"
21+
22+
"github.com/arduino/go-paths-helper"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestCompilationDatabase(t *testing.T) {
27+
tmpfile, err := paths.WriteToTempFile([]byte{}, nil, "")
28+
require.NoError(t, err)
29+
defer tmpfile.Remove()
30+
31+
cmd := exec.Command("gcc", "arg1", "arg2")
32+
db := NewCompilationDatabase(tmpfile)
33+
db.Add(paths.New("test"), cmd)
34+
db.SaveToFile()
35+
36+
db2, err := LoadCompilationDatabase(tmpfile)
37+
require.NoError(t, err)
38+
require.Equal(t, db, db2)
39+
require.Len(t, db2.Contents, 1)
40+
require.Equal(t, db2.Contents[0].File, "test")
41+
require.Equal(t, db2.Contents[0].Command, "")
42+
require.Equal(t, db2.Contents[0].Arguments, []string{"gcc", "arg1", "arg2"})
43+
cwd, err := paths.Getwd()
44+
require.NoError(t, err)
45+
require.Equal(t, db2.Contents[0].Directory, cwd.String())
46+
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
7-
github.com/arduino/go-paths-helper v1.3.2
7+
github.com/arduino/go-paths-helper v1.4.0
88
github.com/arduino/go-properties-orderedmap v1.3.0
99
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1010
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3
1717
github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
1818
github.com/arduino/go-paths-helper v1.3.2 h1:5U9TSKQODiwSVgTxskC0PNl0l0Vf40GUlp99Zy2SK8w=
1919
github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
20+
github.com/arduino/go-paths-helper v1.4.0 h1:ilnseAdxmN1bFnLxxXHRtcdmt9jBf3O4jtYfWfqule4=
21+
github.com/arduino/go-paths-helper v1.4.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
2022
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
2123
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
2224
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=

0 commit comments

Comments
 (0)