diff --git a/arduino/builder/sketch_test.go b/arduino/builder/sketch_test.go index 9df1de917e0..7b535203d6d 100644 --- a/arduino/builder/sketch_test.go +++ b/arduino/builder/sketch_test.go @@ -289,3 +289,35 @@ func TestSketchWithMarkdownAsciidocJson(t *testing.T) { require.Equal(t, "foo.json", filepath.Base(sketch.RootFolderFiles[1].Path)) require.Equal(t, "foo.md", filepath.Base(sketch.RootFolderFiles[2].Path)) } + +func TestSketchWithTppFile(t *testing.T) { + sketchPath := filepath.Join("testdata", t.Name()) + mainFilePath := filepath.Join(sketchPath, t.Name()+".ino") + + sketch, err := builder.SketchLoad(sketchPath, "") + require.NotNil(t, sketch) + require.NoError(t, err) + require.Equal(t, sketchPath, sketch.LocationPath) + require.Equal(t, mainFilePath, sketch.MainFile.Path) + require.Len(t, sketch.OtherSketchFiles, 0) + require.Len(t, sketch.AdditionalFiles, 1) + require.Equal(t, "template.tpp", filepath.Base(sketch.AdditionalFiles[0].Path)) + require.Len(t, sketch.RootFolderFiles, 1) + require.Equal(t, "template.tpp", filepath.Base(sketch.RootFolderFiles[0].Path)) +} + +func TestSketchWithIppFile(t *testing.T) { + sketchPath := filepath.Join("testdata", t.Name()) + mainFilePath := filepath.Join(sketchPath, t.Name()+".ino") + + sketch, err := builder.SketchLoad(sketchPath, "") + require.NotNil(t, sketch) + require.NoError(t, err) + require.Equal(t, sketchPath, sketch.LocationPath) + require.Equal(t, mainFilePath, sketch.MainFile.Path) + require.Len(t, sketch.OtherSketchFiles, 0) + require.Len(t, sketch.AdditionalFiles, 1) + require.Equal(t, "template.ipp", filepath.Base(sketch.AdditionalFiles[0].Path)) + require.Len(t, sketch.RootFolderFiles, 1) + require.Equal(t, "template.ipp", filepath.Base(sketch.RootFolderFiles[0].Path)) +} diff --git a/arduino/builder/testdata/TestSketchWithIppFile/TestSketchWithIppFile.ino b/arduino/builder/testdata/TestSketchWithIppFile/TestSketchWithIppFile.ino new file mode 100644 index 00000000000..51fe991dfd3 --- /dev/null +++ b/arduino/builder/testdata/TestSketchWithIppFile/TestSketchWithIppFile.ino @@ -0,0 +1,4 @@ +#include "template.ipp" + +void setup() {} +void loop() {} diff --git a/arduino/builder/testdata/TestSketchWithIppFile/template.ipp b/arduino/builder/testdata/TestSketchWithIppFile/template.ipp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/arduino/builder/testdata/TestSketchWithTppFile/TestSketchWithTppFile.ino b/arduino/builder/testdata/TestSketchWithTppFile/TestSketchWithTppFile.ino new file mode 100644 index 00000000000..c80cfdac402 --- /dev/null +++ b/arduino/builder/testdata/TestSketchWithTppFile/TestSketchWithTppFile.ino @@ -0,0 +1,4 @@ +#include "template.tpp" + +void setup() {} +void loop() {} diff --git a/arduino/builder/testdata/TestSketchWithTppFile/template.tpp b/arduino/builder/testdata/TestSketchWithTppFile/template.tpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/arduino/globals/globals.go b/arduino/globals/globals.go index 4b3d972912f..4314e03588c 100644 --- a/arduino/globals/globals.go +++ b/arduino/globals/globals.go @@ -39,6 +39,8 @@ var ( ".adoc": empty, ".md": empty, ".json": empty, + ".tpp": empty, + ".ipp": empty, } // SourceFilesValidExtensions lists valid extensions for source files (no headers) diff --git a/arduino/sketch/sketch_test.go b/arduino/sketch/sketch_test.go index 6ed50a6c895..8136b679645 100644 --- a/arduino/sketch/sketch_test.go +++ b/arduino/sketch/sketch_test.go @@ -138,3 +138,37 @@ func TestSketchWithMarkdownAsciidocJson(t *testing.T) { require.Equal(t, "foo.json", filepath.Base(sketch.RootFolderFiles[1].Path)) require.Equal(t, "foo.md", filepath.Base(sketch.RootFolderFiles[2].Path)) } + +func TestSketchWithTppFile(t *testing.T) { + sketchPath := paths.New("testdata", "SketchWithTppFile") + mainFilePath := sketchPath.Join("SketchWithTppFile.ino").String() + templateFile := sketchPath.Join("template.tpp").String() + + sketch, err := New(sketchPath.String(), mainFilePath, "", []string{mainFilePath, templateFile}) + require.NotNil(t, sketch) + require.NoError(t, err) + require.Equal(t, sketchPath.String(), sketch.LocationPath) + require.Equal(t, mainFilePath, sketch.MainFile.Path) + require.Len(t, sketch.OtherSketchFiles, 0) + require.Len(t, sketch.AdditionalFiles, 1) + require.Equal(t, "template.tpp", filepath.Base(sketch.AdditionalFiles[0].Path)) + require.Len(t, sketch.RootFolderFiles, 1) + require.Equal(t, "template.tpp", filepath.Base(sketch.RootFolderFiles[0].Path)) +} + +func TestSketchWithIppFile(t *testing.T) { + sketchPath := paths.New("testdata", "SketchWithIppFile") + mainFilePath := sketchPath.Join("SketchWithIppFile.ino").String() + templateFile := sketchPath.Join("template.ipp").String() + + sketch, err := New(sketchPath.String(), mainFilePath, "", []string{mainFilePath, templateFile}) + require.NotNil(t, sketch) + require.NoError(t, err) + require.Equal(t, sketchPath.String(), sketch.LocationPath) + require.Equal(t, mainFilePath, sketch.MainFile.Path) + require.Len(t, sketch.OtherSketchFiles, 0) + require.Len(t, sketch.AdditionalFiles, 1) + require.Equal(t, "template.ipp", filepath.Base(sketch.AdditionalFiles[0].Path)) + require.Len(t, sketch.RootFolderFiles, 1) + require.Equal(t, "template.ipp", filepath.Base(sketch.RootFolderFiles[0].Path)) +} diff --git a/arduino/sketch/testdata/SketchWithIppFile/SketchWithIppFile.ino b/arduino/sketch/testdata/SketchWithIppFile/SketchWithIppFile.ino new file mode 100644 index 00000000000..51fe991dfd3 --- /dev/null +++ b/arduino/sketch/testdata/SketchWithIppFile/SketchWithIppFile.ino @@ -0,0 +1,4 @@ +#include "template.ipp" + +void setup() {} +void loop() {} diff --git a/arduino/sketch/testdata/SketchWithIppFile/template.ipp b/arduino/sketch/testdata/SketchWithIppFile/template.ipp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/arduino/sketch/testdata/SketchWithTppFile/SketchWithTppFile.ino b/arduino/sketch/testdata/SketchWithTppFile/SketchWithTppFile.ino new file mode 100644 index 00000000000..c80cfdac402 --- /dev/null +++ b/arduino/sketch/testdata/SketchWithTppFile/SketchWithTppFile.ino @@ -0,0 +1,4 @@ +#include "template.tpp" + +void setup() {} +void loop() {} diff --git a/arduino/sketch/testdata/SketchWithTppFile/template.tpp b/arduino/sketch/testdata/SketchWithTppFile/template.tpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/test_compile.py b/test/test_compile.py index eebb47881b6..82de3ef84e8 100644 --- a/test/test_compile.py +++ b/test/test_compile.py @@ -1129,3 +1129,29 @@ def test_compile_with_esp8266_bundled_libraries(run_command, data_dir, copy_sket f" Not used: {cli_installed_lib_path}", ] assert "\n".join(expected_output) not in res.stdout + + +def test_compile_sketch_with_tpp_file_include(run_command, copy_sketch): + assert run_command("update") + + # Download latest AVR + run_command("core install arduino:avr") + + sketch_name = "sketch_with_tpp_file_include" + sketch_path = copy_sketch(sketch_name) + fqbn = "arduino:avr:uno" + + assert run_command(f"compile -b {fqbn} {sketch_path} --verbose") + + +def test_compile_sketch_with_ipp_file_include(run_command, copy_sketch): + assert run_command("update") + + # Download latest AVR + run_command("core install arduino:avr") + + sketch_name = "sketch_with_ipp_file_include" + sketch_path = copy_sketch(sketch_name) + fqbn = "arduino:avr:uno" + + assert run_command(f"compile -b {fqbn} {sketch_path} --verbose") diff --git a/test/testdata/sketch_with_ipp_file_include/sketch_with_ipp_file_include.ino b/test/testdata/sketch_with_ipp_file_include/sketch_with_ipp_file_include.ino new file mode 100644 index 00000000000..51fe991dfd3 --- /dev/null +++ b/test/testdata/sketch_with_ipp_file_include/sketch_with_ipp_file_include.ino @@ -0,0 +1,4 @@ +#include "template.ipp" + +void setup() {} +void loop() {} diff --git a/test/testdata/sketch_with_ipp_file_include/template.ipp b/test/testdata/sketch_with_ipp_file_include/template.ipp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/testdata/sketch_with_tpp_file_include/sketch_with_tpp_file_include.ino b/test/testdata/sketch_with_tpp_file_include/sketch_with_tpp_file_include.ino new file mode 100644 index 00000000000..c80cfdac402 --- /dev/null +++ b/test/testdata/sketch_with_tpp_file_include/sketch_with_tpp_file_include.ino @@ -0,0 +1,4 @@ +#include "template.tpp" + +void setup() {} +void loop() {} diff --git a/test/testdata/sketch_with_tpp_file_include/template.tpp b/test/testdata/sketch_with_tpp_file_include/template.tpp new file mode 100644 index 00000000000..e69de29bb2d