@@ -25,6 +25,33 @@ import (
2525 "gopkg.in/src-d/go-git.v4/plumbing"
2626)
2727
28+ func TestCompilePart3 (t * testing.T ) {
29+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
30+ defer env .CleanUp ()
31+
32+ _ , _ , err := cli .Run ("update" )
33+ require .NoError (t , err )
34+
35+ // Manually installs a core in sketchbooks hardware folder
36+ gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
37+ repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
38+ _ , err = git .PlainClone (repoDir .String (), false , & git.CloneOptions {
39+ URL : gitUrl ,
40+ ReferenceName : plumbing .NewTagReferenceName ("1.8.3" ),
41+ })
42+ require .NoError (t , err )
43+
44+ // Installs also the same core via CLI so all the necessary tools are installed
45+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
46+ require .NoError (t , err )
47+
48+ integrationtest.CLISubtests {
49+ {"ManuallyInstalledPlatform" , compileManuallyInstalledPlatform },
50+ {"ManuallyInstalledPlatformUsingPlatformLocalTxt" , compileManuallyInstalledPlatformUsingPlatformLocalTxt },
51+ {"ManuallyInstalledPlatformUsingBoardsLocalTxt" , compileManuallyInstalledPlatformUsingBoardsLocalTxt },
52+ }.Run (t , env , cli )
53+ }
54+
2855func TestCompileWithFullyPrecompiledLibrary (t * testing.T ) {
2956 env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
3057 defer env .CleanUp ()
@@ -61,73 +88,65 @@ func TestCompileWithFullyPrecompiledLibrary(t *testing.T) {
6188 require .Contains (t , string (stdout ), "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite" )
6289}
6390
64- func TestCompileManuallyInstalledPlatform (t * testing.T ) {
65- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
66- defer env .CleanUp ()
67-
68- _ , _ , err := cli .Run ("update" )
69- require .NoError (t , err )
70-
91+ func compileManuallyInstalledPlatform (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
7192 sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt"
7293 sketchPath := cli .SketchbookDir ().Join (sketchName )
94+ defer sketchPath .RemoveAll ()
7395 fqbn := "arduino-beta-development:avr:uno"
74- _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
75- require .NoError (t , err )
76-
77- // Manually installs a core in sketchbooks hardware folder
78- gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
79- repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
80- _ , err = git .PlainClone (repoDir .String (), false , & git.CloneOptions {
81- URL : gitUrl ,
82- ReferenceName : plumbing .NewTagReferenceName ("1.8.3" ),
83- })
84- require .NoError (t , err )
85-
86- // Installs also the same core via CLI so all the necessary tools are installed
87- _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
96+ _ , _ , err := cli .Run ("sketch" , "new" , sketchPath .String ())
8897 require .NoError (t , err )
8998
9099 // Verifies compilation works without issues
91100 _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
92101 require .NoError (t , err )
93102}
94103
95- func TestCompileManuallyInstalledPlatformUsingPlatformLocalTxt (t * testing.T ) {
96- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
97- defer env .CleanUp ()
98-
99- _ , _ , err := cli .Run ("update" )
100- require .NoError (t , err )
101-
104+ func compileManuallyInstalledPlatformUsingPlatformLocalTxt (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
102105 sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt"
103106 sketchPath := cli .SketchbookDir ().Join (sketchName )
107+ defer sketchPath .RemoveAll ()
104108 fqbn := "arduino-beta-development:avr:uno"
105- _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
106- require .NoError (t , err )
107-
108- // Manually installs a core in sketchbooks hardware folder
109- gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
110- repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
111- _ , err = git .PlainClone (repoDir .String (), false , & git.CloneOptions {
112- URL : gitUrl ,
113- ReferenceName : plumbing .NewTagReferenceName ("1.8.3" ),
114- })
115- require .NoError (t , err )
116-
117- // Installs also the same core via CLI so all the necessary tools are installed
118- _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
109+ _ , _ , err := cli .Run ("sketch" , "new" , sketchPath .String ())
119110 require .NoError (t , err )
120111
121112 // Verifies compilation works without issues
122113 _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
123114 require .NoError (t , err )
124115
125116 // Overrides default platform compiler with an unexisting one
117+ repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
126118 platformLocalTxt := repoDir .Join ("platform.local.txt" )
119+ defer platformLocalTxt .Remove ()
127120 platformLocalTxt .WriteFile ([]byte ("compiler.c.cmd=my-compiler-that-does-not-exist" ))
128121
129122 // Verifies compilation now fails because compiler is not found
130123 _ , stderr , err := cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
131124 require .Error (t , err )
132125 require .Contains (t , string (stderr ), "my-compiler-that-does-not-exist" )
133126}
127+
128+ func compileManuallyInstalledPlatformUsingBoardsLocalTxt (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
129+ sketchName := "CompileSketchManuallyInstalledPlatformUsingBoardsLocalTxt"
130+ sketchPath := cli .SketchbookDir ().Join (sketchName )
131+ defer sketchPath .RemoveAll ()
132+ fqbn := "arduino-beta-development:avr:nessuno"
133+ _ , _ , err := cli .Run ("sketch" , "new" , sketchPath .String ())
134+ require .NoError (t , err )
135+
136+ // Verifies compilation fails because board doesn't exist
137+ _ , stderr , err := cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
138+ require .Error (t , err )
139+ require .Contains (t , string (stderr ), "Error during build: Error resolving FQBN: board arduino-beta-development:avr:nessuno not found" )
140+
141+ // Use custom boards.local.txt with made arduino:avr:nessuno board
142+ repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
143+ boardsLocalTxt := repoDir .Join ("boards.local.txt" )
144+ defer boardsLocalTxt .Remove ()
145+ wd , err := paths .Getwd ()
146+ require .NoError (t , err )
147+ err = wd .Parent ().Join ("testdata" , "boards.local.txt" ).CopyTo (boardsLocalTxt )
148+ require .NoError (t , err )
149+
150+ _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
151+ require .NoError (t , err )
152+ }
0 commit comments