@@ -32,47 +32,72 @@ package test
3232import (
3333 "arduino.cc/builder"
3434 "arduino.cc/builder/constants"
35+ "arduino.cc/builder/types"
3536 "github.com/stretchr/testify/require"
3637 "os"
3738 "path/filepath"
3839 "testing"
3940)
4041
41- func TestCreateBuildPathIfMissing (t * testing.T ) {
42+ func TestGenerateBuildPathIfMissing (t * testing.T ) {
4243 context := make (map [string ]interface {})
4344
4445 context [constants .CTX_SKETCH_LOCATION ] = "test"
4546
46- createBuildPathIfMissing := builder.CreateBuildPathIfMissing {}
47- err := createBuildPathIfMissing .Run (context )
47+ command := builder.GenerateBuildPathIfMissing {}
48+ err := command .Run (context )
4849 NoError (t , err )
4950
5051 require .Equal (t , filepath .Join (os .TempDir (), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6" ), context [constants .CTX_BUILD_PATH ])
51- os .RemoveAll (context [constants .CTX_BUILD_PATH ].(string ))
52+ _ , err = os .Stat (filepath .Join (os .TempDir (), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6" ))
53+ require .True (t , os .IsNotExist (err ))
5254}
5355
54- func TestCreateBuildPathIfEmpty (t * testing.T ) {
56+ func TestGenerateBuildPathIfEmpty (t * testing.T ) {
5557 context := make (map [string ]interface {})
5658
5759 context [constants .CTX_SKETCH_LOCATION ] = "test"
5860 context [constants .CTX_BUILD_PATH ] = constants .EMPTY_STRING
5961
60- createBuildPathIfMissing := builder.CreateBuildPathIfMissing {}
62+ createBuildPathIfMissing := builder.GenerateBuildPathIfMissing {}
6163 err := createBuildPathIfMissing .Run (context )
6264 NoError (t , err )
6365
6466 require .Equal (t , filepath .Join (os .TempDir (), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6" ), context [constants .CTX_BUILD_PATH ])
65- os .RemoveAll (context [constants .CTX_BUILD_PATH ].(string ))
67+ _ , err = os .Stat (filepath .Join (os .TempDir (), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6" ))
68+ require .True (t , os .IsNotExist (err ))
6669}
6770
68- func TestDontCreateBuildPathIfPresent (t * testing.T ) {
71+ func TestDontGenerateBuildPathIfPresent (t * testing.T ) {
6972 context := make (map [string ]interface {})
7073
7174 context [constants .CTX_BUILD_PATH ] = "test"
7275
73- createBuildPathIfMissing := builder.CreateBuildPathIfMissing {}
76+ createBuildPathIfMissing := builder.GenerateBuildPathIfMissing {}
7477 err := createBuildPathIfMissing .Run (context )
7578 NoError (t , err )
7679
7780 require .Equal (t , "test" , context [constants .CTX_BUILD_PATH ])
7881}
82+
83+ func TestGenerateBuildPathAndEnsureItExists (t * testing.T ) {
84+ context := make (map [string ]interface {})
85+
86+ context [constants .CTX_SKETCH_LOCATION ] = "test"
87+
88+ commands := []types.Command {
89+ & builder.GenerateBuildPathIfMissing {},
90+ & builder.EnsureBuildPathExists {},
91+ }
92+
93+ for _ , command := range commands {
94+ err := command .Run (context )
95+ NoError (t , err )
96+ }
97+
98+ defer os .RemoveAll (filepath .Join (os .TempDir (), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6" ))
99+
100+ require .Equal (t , filepath .Join (os .TempDir (), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6" ), context [constants .CTX_BUILD_PATH ])
101+ _ , err := os .Stat (filepath .Join (os .TempDir (), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6" ))
102+ NoError (t , err )
103+ }
0 commit comments