|  | 
|  | 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 license@arduino.cc. | 
|  | 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 | +} | 
0 commit comments