From 9899c6680183af1e876209122078a65d3c2aed27 Mon Sep 17 00:00:00 2001 From: tshcherban Date: Mon, 14 Jun 2021 09:13:27 +0300 Subject: [PATCH 1/3] added '.tpp' file ext to known list --- arduino/globals/globals.go | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino/globals/globals.go b/arduino/globals/globals.go index 4b3d972912f..a40e2d53a62 100644 --- a/arduino/globals/globals.go +++ b/arduino/globals/globals.go @@ -39,6 +39,7 @@ var ( ".adoc": empty, ".md": empty, ".json": empty, + ".tpp": empty, } // SourceFilesValidExtensions lists valid extensions for source files (no headers) From 7cebec824c60af458ab0f07c1b8dcd42824d53d4 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Mon, 21 Jun 2021 16:00:24 +0200 Subject: [PATCH 2/3] Add support for .ipp Sketch files extension --- arduino/globals/globals.go | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino/globals/globals.go b/arduino/globals/globals.go index a40e2d53a62..4314e03588c 100644 --- a/arduino/globals/globals.go +++ b/arduino/globals/globals.go @@ -40,6 +40,7 @@ var ( ".md": empty, ".json": empty, ".tpp": empty, + ".ipp": empty, } // SourceFilesValidExtensions lists valid extensions for source files (no headers) From efb65bd9ea0d69e4db22a314c1bd9524850c4da3 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Mon, 21 Jun 2021 16:35:50 +0200 Subject: [PATCH 3/3] Add tests for new .tpp and .ipp extensions suppport --- arduino/builder/sketch_test.go | 32 +++++++++++++++++ .../TestSketchWithIppFile.ino | 4 +++ .../TestSketchWithIppFile/template.ipp | 0 .../TestSketchWithTppFile.ino | 4 +++ .../TestSketchWithTppFile/template.tpp | 0 arduino/sketch/sketch_test.go | 34 +++++++++++++++++++ .../SketchWithIppFile/SketchWithIppFile.ino | 4 +++ .../testdata/SketchWithIppFile/template.ipp | 0 .../SketchWithTppFile/SketchWithTppFile.ino | 4 +++ .../testdata/SketchWithTppFile/template.tpp | 0 test/test_compile.py | 26 ++++++++++++++ .../sketch_with_ipp_file_include.ino | 4 +++ .../sketch_with_ipp_file_include/template.ipp | 0 .../sketch_with_tpp_file_include.ino | 4 +++ .../sketch_with_tpp_file_include/template.tpp | 0 15 files changed, 116 insertions(+) create mode 100644 arduino/builder/testdata/TestSketchWithIppFile/TestSketchWithIppFile.ino create mode 100644 arduino/builder/testdata/TestSketchWithIppFile/template.ipp create mode 100644 arduino/builder/testdata/TestSketchWithTppFile/TestSketchWithTppFile.ino create mode 100644 arduino/builder/testdata/TestSketchWithTppFile/template.tpp create mode 100644 arduino/sketch/testdata/SketchWithIppFile/SketchWithIppFile.ino create mode 100644 arduino/sketch/testdata/SketchWithIppFile/template.ipp create mode 100644 arduino/sketch/testdata/SketchWithTppFile/SketchWithTppFile.ino create mode 100644 arduino/sketch/testdata/SketchWithTppFile/template.tpp create mode 100644 test/testdata/sketch_with_ipp_file_include/sketch_with_ipp_file_include.ino create mode 100644 test/testdata/sketch_with_ipp_file_include/template.ipp create mode 100644 test/testdata/sketch_with_tpp_file_include/sketch_with_tpp_file_include.ino create mode 100644 test/testdata/sketch_with_tpp_file_include/template.tpp 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/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