|
| 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 Steve Marple |
| 28 | + */ |
| 29 | + |
| 30 | +package test |
| 31 | + |
| 32 | +import ( |
| 33 | + "arduino.cc/builder" |
| 34 | + "arduino.cc/builder/constants" |
| 35 | + "github.com/stretchr/testify/require" |
| 36 | + "path/filepath" |
| 37 | + "testing" |
| 38 | +) |
| 39 | + |
| 40 | +func TestSketchWithNoBuildProps(t *testing.T) { |
| 41 | + var err error |
| 42 | + context := make(map[string]interface{}) |
| 43 | + |
| 44 | + context[constants.CTX_BUILD_PATH] = "buildPath" |
| 45 | + context[constants.CTX_HARDWARE_FOLDERS] = []string{"hardware"} |
| 46 | + context[constants.CTX_TOOLS_FOLDERS] = []string{"tools"} |
| 47 | + context[constants.CTX_LIBRARIES_FOLDERS] = []string{"libraries"} |
| 48 | + context[constants.CTX_FQBN] = "fqbn" |
| 49 | + context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_no_props", "sketch.ino") |
| 50 | + |
| 51 | + context[constants.CTX_VERBOSE] = true |
| 52 | + context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "ideVersion" |
| 53 | + context[constants.CTX_SKETCH_BUILD_PROPERTIES], err = builder.GetSketchBuildProperties(context) |
| 54 | + NoError(t, err) |
| 55 | + |
| 56 | + context[constants.CTX_DEBUG_LEVEL] = 5 |
| 57 | + |
| 58 | + create := builder.CreateBuildOptionsMap{} |
| 59 | + err = create.Run(context) |
| 60 | + NoError(t, err) |
| 61 | + |
| 62 | + buildOptions := context[constants.CTX_BUILD_OPTIONS].(map[string]interface{}) |
| 63 | + sketchBuildProps := make(map[string]string) |
| 64 | + require.Equal(t, sketchBuildProps, buildOptions[constants.CTX_SKETCH_BUILD_PROPERTIES]) |
| 65 | +} |
| 66 | + |
| 67 | +func TestSketchWithBuildProps(t *testing.T) { |
| 68 | + var err error |
| 69 | + context := make(map[string]interface{}) |
| 70 | + |
| 71 | + context[constants.CTX_BUILD_PATH] = "buildPath" |
| 72 | + context[constants.CTX_HARDWARE_FOLDERS] = []string{"hardware"} |
| 73 | + context[constants.CTX_TOOLS_FOLDERS] = []string{"tools"} |
| 74 | + context[constants.CTX_LIBRARIES_FOLDERS] = []string{"libraries"} |
| 75 | + context[constants.CTX_FQBN] = "fqbn" |
| 76 | + context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_props", "sketch.ino") |
| 77 | + |
| 78 | + context[constants.CTX_VERBOSE] = true |
| 79 | + context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "ideVersion" |
| 80 | + context[constants.CTX_SKETCH_BUILD_PROPERTIES], err = builder.GetSketchBuildProperties(context) |
| 81 | + NoError(t, err) |
| 82 | + |
| 83 | + context[constants.CTX_DEBUG_LEVEL] = 5 |
| 84 | + |
| 85 | + create := builder.CreateBuildOptionsMap{} |
| 86 | + err = create.Run(context) |
| 87 | + NoError(t, err) |
| 88 | + |
| 89 | + buildOptions := context[constants.CTX_BUILD_OPTIONS].(map[string]interface{}) |
| 90 | + sketchBuildProps := make(map[string]string) |
| 91 | + sketchBuildProps["compiler.c.extra_flags"] = "-D NDEBUG" |
| 92 | + sketchBuildProps["compiler.cpp.extra_flags"] = "-D NDEBUG -D TESTLIBRARY_BUFSIZE=100 -D ARDUINO_URL=\"https://www.arduino.cc/\"" |
| 93 | + |
| 94 | + require.Equal(t, sketchBuildProps, buildOptions[constants.CTX_SKETCH_BUILD_PROPERTIES]) |
| 95 | + |
| 96 | +} |
0 commit comments