Skip to content

Added test for building all problematic sketches #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/arduino.cc/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const CTX_CTAGS_OUTPUT = "ctagsOutput"
const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath"
const CTX_CUSTOM_BUILD_PROPERTIES = "customBuildProperties"
const CTX_DEBUG_LEVEL = "debugLevel"
const CTX_DEBUG_PREPROCESSOR = "debugPreprocessor"
const CTX_FILE_PATH_TO_READ = "filePathToRead"
const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue"
const CTX_FQBN = "fqbn"
Expand Down
17 changes: 17 additions & 0 deletions src/arduino.cc/builder/prototypes_adder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ import (
"arduino.cc/builder/constants"
"arduino.cc/builder/types"
"arduino.cc/builder/utils"
"fmt"
"strconv"
"strings"
)

type PrototypesAdder struct{}

func (s *PrototypesAdder) Run(context map[string]interface{}) error {
debugOutput := context[constants.CTX_DEBUG_PREPROCESSOR] != nil
source := context[constants.CTX_SOURCE].(string)
sourceRows := strings.Split(source, "\n")

Expand All @@ -58,6 +60,21 @@ func (s *PrototypesAdder) Run(context map[string]interface{}) error {
context[constants.CTX_PROTOTYPE_SECTION] = prototypeSection
source = source[:firstFunctionChar] + prototypeSection + source[firstFunctionChar:]

if debugOutput {
fmt.Println("#PREPROCESSED SOURCE")
prototypesRows := strings.Split(prototypeSection, "\n")
prototypesRows = prototypesRows[:len(prototypesRows)-1]
for i := 0; i < len(sourceRows)+len(prototypesRows); i++ {
if i < insertionLine {
fmt.Printf(" |%s\n", sourceRows[i])
} else if i < insertionLine+len(prototypesRows) {
fmt.Printf("PRO|%s\n", prototypesRows[i-insertionLine])
} else {
fmt.Printf(" |%s\n", sourceRows[i-len(prototypesRows)])
}
}
fmt.Println("#END OF PREPROCESSED SOURCE")
}
context[constants.CTX_SOURCE] = source

return nil
Expand Down
7 changes: 1 addition & 6 deletions src/arduino.cc/builder/test/downloaded_libraries/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
A*
B*
C*
H*
P*
R*
*
1 change: 1 addition & 0 deletions src/arduino.cc/builder/test/helper_tools_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func DownloadCoresAndToolsAndLibraries(t *testing.T) {
Library{Name: "Adafruit PN532", Version: "1.0.0"},
Library{Name: "Bridge", Version: "1.1.0"},
Library{Name: "CapacitiveSensor", Version: "0.5.0", VersionInLibProperties: "0.5"},
Library{Name: "Ethernet", Version: "1.1.1"},
Library{Name: "Robot IR Remote", Version: "1.0.2"},
}

Expand Down
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/test/includes_finder_with_gcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin
require.Equal(t, "SPI", importedLibraries[0].Name)
}

func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet(t *testing.T) {
func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndIncludesMissingLib(t *testing.T) {
DownloadCoresAndToolsAndLibraries(t)

context := make(map[string]interface{})
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude
includes := context[constants.CTX_INCLUDES].([]string)
require.Equal(t, 2, len(includes))
sort.Strings(includes)
require.Equal(t, "Ethernet.h", includes[0])
require.Equal(t, "Inexistent.h", includes[0])
require.Equal(t, "SPI.h", includes[1])

importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
Expand Down
8 changes: 6 additions & 2 deletions src/arduino.cc/builder/test/libraries_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestLoadLibrariesAVR(t *testing.T) {
require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2])

libraries := context[constants.CTX_LIBRARIES].([]*types.Library)
require.Equal(t, 18, len(libraries))
require.Equal(t, 19, len(libraries))

sort.Sort(ByLibraryName(libraries))

Expand Down Expand Up @@ -107,6 +107,8 @@ func TestLoadLibrariesAVR(t *testing.T) {
idx++
require.Equal(t, "EEPROM", libraries[idx].Name)
idx++
require.Equal(t, "Ethernet", libraries[idx].Name)
idx++
require.Equal(t, "FakeAudio", libraries[idx].Name)
idx++
require.Equal(t, "HID", libraries[idx].Name)
Expand Down Expand Up @@ -175,7 +177,7 @@ func TestLoadLibrariesSAM(t *testing.T) {
require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2])

libraries := context[constants.CTX_LIBRARIES].([]*types.Library)
require.Equal(t, 16, len(libraries))
require.Equal(t, 17, len(libraries))

sort.Sort(ByLibraryName(libraries))

Expand All @@ -192,6 +194,8 @@ func TestLoadLibrariesSAM(t *testing.T) {
idx++
require.Equal(t, "CapacitiveSensor", libraries[idx].Name)
idx++
require.Equal(t, "Ethernet", libraries[idx].Name)
idx++
require.Equal(t, "FakeAudio", libraries[idx].Name)
idx++
require.Equal(t, "HID", libraries[idx].Name)
Expand Down
28 changes: 25 additions & 3 deletions src/arduino.cc/builder/test/prototypes_adder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,12 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) {
}

preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), context)
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
obtained := strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)
// ctags based preprocessing removes the space after "dostuff", but this is still OK
// TODO: remove this exception when moving to a more powerful parser
preprocessed = strings.Replace(preprocessed, "void dostuff (A_NEW_TYPE * bar);", "void dostuff(A_NEW_TYPE * bar);", 1)
obtained = strings.Replace(obtained, "void dostuff (A_NEW_TYPE * bar);", "void dostuff(A_NEW_TYPE * bar);", 1)
require.Equal(t, preprocessed, obtained)
}

func TestPrototypesAdderSketchWithConfig(t *testing.T) {
Expand Down Expand Up @@ -587,7 +592,18 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
}

require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nshort unsigned int testInt();\n#line 8 \""+absoluteSketchLocation+"\"\nstatic int8_t testInline();\n#line 12 \""+absoluteSketchLocation+"\"\nuint8_t testAttribute();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))

expected := "#line 1 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 2 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 4 \"" + absoluteSketchLocation + "\"\nshort unsigned int testInt();\n#line 8 \"" + absoluteSketchLocation + "\"\nstatic int8_t testInline();\n#line 12 \"" + absoluteSketchLocation + "\"\n__attribute__((always_inline)) uint8_t testAttribute();\n#line 1\n"
obtained := context[constants.CTX_PROTOTYPE_SECTION].(string)
// ctags based preprocessing removes "inline" but this is still OK
// TODO: remove this exception when moving to a more powerful parser
expected = strings.Replace(expected, "static inline int8_t testInline();", "static int8_t testInline();", -1)
obtained = strings.Replace(obtained, "static inline int8_t testInline();", "static int8_t testInline();", -1)
// ctags based preprocessing removes "__attribute__ ....." but this is still OK
// TODO: remove this exception when moving to a more powerful parser
expected = strings.Replace(expected, "__attribute__((always_inline)) uint8_t testAttribute();", "uint8_t testAttribute();", -1)
obtained = strings.Replace(obtained, "__attribute__((always_inline)) uint8_t testAttribute();", "uint8_t testAttribute();", -1)
require.Equal(t, expected, obtained)
}

func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {
Expand Down Expand Up @@ -718,7 +734,13 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) {
}

require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
require.Equal(t, "#line 6 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 6\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
expected := "#line 6 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 10 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 12 \"" + absoluteSketchLocation + "\"\ntypename Foo<char>::Bar func();\n#line 6\n"
obtained := context[constants.CTX_PROTOTYPE_SECTION].(string)
// ctags based preprocessing ignores line with typename
// TODO: remove this exception when moving to a more powerful parser
expected = strings.Replace(expected, "#line 12 \""+absoluteSketchLocation+"\"\ntypename Foo<char>::Bar func();\n", "", -1)
obtained = strings.Replace(obtained, "#line 12 \""+absoluteSketchLocation+"\"\ntypename Foo<char>::Bar func();\n", "", -1)
require.Equal(t, expected, obtained)
}

func TestPrototypesAdderSketchWithIfDef2(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/test/sketch10/sketch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#include <IRremoteInt.h>

void setup() {}
void main() {}
void loop() {}
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/test/sketch2/SketchWithIfDef.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define DEBUG 1
#define DISABLED 0

typedef MyType int;
typedef int MyType;

#if DISABLED
#include <debug.h>
Expand Down Expand Up @@ -47,4 +47,4 @@ void disabledIsDefined() {

int useMyType(MyType type) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define DEBUG 1
#define DISABLED 0

typedef MyType int;
typedef int MyType;

#if DISABLED
#include <debug.h>
Expand Down Expand Up @@ -62,3 +62,4 @@ void disabledIsDefined() {
int useMyType(MyType type) {

}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define DEBUG 1
#define DISABLED 0

typedef MyType int;
typedef int MyType;



Expand Down Expand Up @@ -52,3 +52,4 @@ int useMyType(MyType type) {

}


Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void setup()
}
void loop()
{
long total1 = cs_13_8.read(30);
long total1 = cs_13_8.capacitiveSensor(30);
Serial.println(total1);
delay(100);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void setup()
}
void loop()
{
long total1 = cs_13_8.read(30);
long total1 = cs_13_8.capacitiveSensor(30);
Serial.println(total1);
delay(100);
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void setup();
#line 13 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
void loop();
#line 17 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
void dostuff(A_NEW_TYPE * bar);
void dostuff (A_NEW_TYPE * bar);
#line 9
void setup() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <SPI.h>
#include <Ethernet.h>
#include <Inexistent.h>

#if !defined(SPI_HAS_TRANSACTION) || !SPI_HAS_TRANSACTION
#error "Where is my SPI_HAS_TRANSACTION!?!?"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Task {
public:
Task(void (*aCallback)()) {};
};

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CallbackBug.h"
Task t1(&t1Callback);
void t1Callback() {}
void setup() {}
void loop() {}
void loop() {}
Loading