|
| 1 | +/* |
| 2 | + * This file is part of Arduino Builder. |
| 3 | + * |
| 4 | + * Arduino Builder is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + * |
| 18 | + * As a special exception, you may use this file as part of a free software |
| 19 | + * library without restriction. Specifically, if other files instantiate |
| 20 | + * templates or use macros or inline functions from this file, or you compile |
| 21 | + * this file and link it with other files to produce an executable, this |
| 22 | + * file does not by itself cause the resulting executable to be covered by |
| 23 | + * the GNU General Public License. This exception does not however |
| 24 | + * invalidate any other reasons why the executable file might be covered by |
| 25 | + * the GNU General Public License. |
| 26 | + * |
| 27 | + * Copyright 2015 Arduino LLC (http://www.arduino.cc/) |
| 28 | + */ |
| 29 | + |
| 30 | +package test |
| 31 | + |
| 32 | +import ( |
| 33 | + "arduino.cc/builder" |
| 34 | + "arduino.cc/builder/constants" |
| 35 | + "arduino.cc/builder/types" |
| 36 | + "github.com/stretchr/testify/require" |
| 37 | + "io/ioutil" |
| 38 | + "os" |
| 39 | + "path/filepath" |
| 40 | + "testing" |
| 41 | +) |
| 42 | + |
| 43 | +func TestUnusedCompiledLibrariesRemover(t *testing.T) { |
| 44 | + temp, err := ioutil.TempDir("", "test") |
| 45 | + NoError(t, err) |
| 46 | + defer os.RemoveAll(temp) |
| 47 | + |
| 48 | + NoError(t, os.MkdirAll(filepath.Join(temp, "SPI"), os.FileMode(0755))) |
| 49 | + NoError(t, os.MkdirAll(filepath.Join(temp, "Bridge"), os.FileMode(0755))) |
| 50 | + NoError(t, ioutil.WriteFile(filepath.Join(temp, "dummy_file"), []byte{}, os.FileMode(0644))) |
| 51 | + |
| 52 | + context := make(map[string]interface{}) |
| 53 | + context[constants.CTX_LIBRARIES_BUILD_PATH] = temp |
| 54 | + context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} |
| 55 | + |
| 56 | + cmd := builder.UnusedCompiledLibrariesRemover{} |
| 57 | + err = cmd.Run(context) |
| 58 | + NoError(t, err) |
| 59 | + |
| 60 | + _, err = os.Stat(filepath.Join(temp, "SPI")) |
| 61 | + require.Error(t, err) |
| 62 | + require.True(t, os.IsNotExist(err)) |
| 63 | + _, err = os.Stat(filepath.Join(temp, "Bridge")) |
| 64 | + NoError(t, err) |
| 65 | + _, err = os.Stat(filepath.Join(temp, "dummy_file")) |
| 66 | + NoError(t, err) |
| 67 | +} |
| 68 | + |
| 69 | +func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) { |
| 70 | + context := make(map[string]interface{}) |
| 71 | + context[constants.CTX_LIBRARIES_BUILD_PATH] = filepath.Join(os.TempDir(), "test") |
| 72 | + context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} |
| 73 | + |
| 74 | + cmd := builder.UnusedCompiledLibrariesRemover{} |
| 75 | + err := cmd.Run(context) |
| 76 | + NoError(t, err) |
| 77 | +} |
0 commit comments