|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2023 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 diagnostics |
| 17 | + |
| 18 | +import ( |
| 19 | + "strings" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | +) |
| 24 | + |
| 25 | +func init() { |
| 26 | + runProcess = mockedRunProcessToGetCompilerVersion |
| 27 | +} |
| 28 | + |
| 29 | +func mockedRunProcessToGetCompilerVersion(args ...string) []string { |
| 30 | + if strings.HasSuffix(args[0], "7.3.0-atmel3.6.1-arduino7/bin/avr-g++") && args[1] == "--version" { |
| 31 | + return []string{ |
| 32 | + "avr-g++ (GCC) 7.3.0", |
| 33 | + "Copyright (C) 2017 Free Software Foundation, Inc.", |
| 34 | + "This is free software; see the source for copying conditions. There is NO", |
| 35 | + "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.", |
| 36 | + "", |
| 37 | + } |
| 38 | + } |
| 39 | + if strings.HasSuffix(args[0], "7.3.0-atmel3.6.1-arduino7/bin/avr-gcc") && args[1] == "--version" { |
| 40 | + return []string{ |
| 41 | + "avr-gcc (GCC) 7.3.0", |
| 42 | + "Copyright (C) 2017 Free Software Foundation, Inc.", |
| 43 | + "This is free software; see the source for copying conditions. There is NO", |
| 44 | + "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.", |
| 45 | + "", |
| 46 | + } |
| 47 | + } |
| 48 | + if strings.HasSuffix(args[0], "xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/bin/xtensa-esp32-elf-g++") && args[1] == "--version" { |
| 49 | + return []string{ |
| 50 | + "xtensa-esp32-elf-g++ (crosstool-NG esp-2021r2-patch3) 8.4.0", |
| 51 | + "Copyright (C) 2018 Free Software Foundation, Inc.", |
| 52 | + "This is free software; see the source for copying conditions. There is NO", |
| 53 | + "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.", |
| 54 | + "", |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + panic("missing mock for command line: " + strings.Join(args, " ")) |
| 59 | +} |
| 60 | + |
| 61 | +func TestCompilerDetection(t *testing.T) { |
| 62 | + comp := DetectCompilerFromCommandLine([]string{"~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++"}, true) |
| 63 | + require.NotNil(t, comp) |
| 64 | + require.Equal(t, "gcc", comp.Family) |
| 65 | + require.Equal(t, "avr-g++", comp.Name) |
| 66 | + require.Equal(t, "7.3.0", comp.Version.String()) |
| 67 | + |
| 68 | + comp = DetectCompilerFromCommandLine([]string{"~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc"}, true) |
| 69 | + require.NotNil(t, comp) |
| 70 | + require.Equal(t, "gcc", comp.Family) |
| 71 | + require.Equal(t, "avr-gcc", comp.Name) |
| 72 | + require.Equal(t, "7.3.0", comp.Version.String()) |
| 73 | + |
| 74 | + comp = DetectCompilerFromCommandLine([]string{"/home/megabug/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/bin/xtensa-esp32-elf-g++"}, true) |
| 75 | + require.NotNil(t, comp) |
| 76 | + require.Equal(t, "gcc", comp.Family) |
| 77 | + require.Equal(t, "xtensa-esp32-elf-g++", comp.Name) |
| 78 | + require.Equal(t, "8.4.0", comp.Version.String()) |
| 79 | +} |
0 commit comments