Skip to content

Commit

Permalink
Test include detection with subfolders
Browse files Browse the repository at this point in the history
This verifies that:
 - Source files inside the src/ subfolder of a sketch are subject to
   include detection.
 - Header files included by the main sketch are subject to include
   detection.
 - Source files in other subfolders are *not* subject to include
   detection.

This commit adds four dummy libraries, "testlib1" to "testlib4" that only
contain an empty header file. These can be used to test whether an include
leads to the correct library being included, without running into other
unexpected issues when using real libraries (like one library including
another, or not all libraries being available for all boards, etc.).

Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
  • Loading branch information
matthijskooijman committed Aug 1, 2016
1 parent 3eed66c commit efd06bc
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 6 deletions.
42 changes: 42 additions & 0 deletions src/arduino.cc/builder/test/includes_to_include_folders_test.go
Expand Up @@ -37,6 +37,7 @@ import (
"path/filepath"
"sort"
"testing"
"fmt"
)

func TestIncludesToIncludeFolders(t *testing.T) {
Expand Down Expand Up @@ -298,3 +299,44 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
require.Equal(t, "USBHost", importedLibraries[0].Name)
require.Equal(t, Abs(t, filepath.Join("libraries", "USBHost", "src")), importedLibraries[0].SrcFolder)
}

func TestIncludesToIncludeFoldersSubfolders(t *testing.T) {
DownloadCoresAndToolsAndLibraries(t)

ctx := &types.Context{
HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"},
ToolsFolders: []string{"downloaded_tools"},
BuiltInLibrariesFolders: []string{"downloaded_libraries"},
OtherLibrariesFolders: []string{"libraries"},
SketchLocation: filepath.Join("sketch_with_subfolders", "sketch_with_subfolders.ino"),
FQBN: "arduino:avr:leonardo",
ArduinoAPIVersion: "10600",
Verbose: true,
}

buildPath := SetupBuildPath(t, ctx)
defer os.RemoveAll(buildPath)

commands := []types.Command{

&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},

&builder.ContainerMergeCopySketchFiles{},

&builder.ContainerFindIncludes{},
}

for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}

importedLibraries := ctx.ImportedLibraries
sort.Sort(ByLibraryName(importedLibraries))
fmt.Println(importedLibraries)
require.Equal(t, 3, len(importedLibraries))
require.Equal(t, "testlib1", importedLibraries[0].Name)
require.Equal(t, "testlib2", importedLibraries[1].Name)
require.Equal(t, "testlib3", importedLibraries[2].Name)
}

Empty file.
Empty file.
Empty file.
Empty file.
11 changes: 6 additions & 5 deletions src/arduino.cc/builder/test/libraries_loader_test.go
Expand Up @@ -30,13 +30,14 @@
package test

import (
"path/filepath"
"sort"
"testing"

"arduino.cc/builder"
"arduino.cc/builder/constants"
"arduino.cc/builder/types"
"github.com/stretchr/testify/require"
"path/filepath"
"sort"
"testing"
)

func TestLoadLibrariesAVR(t *testing.T) {
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestLoadLibrariesAVR(t *testing.T) {
require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2])

libraries := ctx.Libraries
require.Equal(t, 20, len(libraries))
require.Equal(t, 24, len(libraries))

sort.Sort(ByLibraryName(libraries))

Expand Down Expand Up @@ -177,7 +178,7 @@ func TestLoadLibrariesSAM(t *testing.T) {
require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2])

libraries := ctx.Libraries
require.Equal(t, 18, len(libraries))
require.Equal(t, 22, len(libraries))

sort.Sort(ByLibraryName(libraries))

Expand Down
@@ -1,3 +1,4 @@
#include <testlib1.h>
#include "subfolder/other.h"
#include "src/subfolder/other.h"

Expand Down
@@ -1,4 +1,5 @@
#include <Arduino.h> // Arduino 1.0
#include <testlib2.h>

#include "other.h"

Expand Down
@@ -1,5 +1,6 @@
#ifndef other__h
#define other__h
#include <testlib3.h>

class MyClass {
public:
Expand All @@ -9,4 +10,4 @@ class MyClass {
private:
Stream *controllerStream;
};
#endif
#endif
@@ -1 +1,2 @@
#include <testlib4.h>
#error "Whattya looking at?"
@@ -1 +1,2 @@
#include <testlib4.h>
#error "Whattya looking at?"

0 comments on commit efd06bc

Please sign in to comment.