@@ -32,47 +32,72 @@ package test
32
32
import (
33
33
"arduino.cc/builder"
34
34
"arduino.cc/builder/constants"
35
+ "arduino.cc/builder/types"
35
36
"github.com/stretchr/testify/require"
36
37
"os"
37
38
"path/filepath"
38
39
"testing"
39
40
)
40
41
41
- func TestCreateBuildPathIfMissing (t * testing.T ) {
42
+ func TestGenerateBuildPathIfMissing (t * testing.T ) {
42
43
context := make (map [string ]interface {})
43
44
44
45
context [constants .CTX_SKETCH_LOCATION ] = "test"
45
46
46
- createBuildPathIfMissing := builder.CreateBuildPathIfMissing {}
47
- err := createBuildPathIfMissing .Run (context )
47
+ command := builder.GenerateBuildPathIfMissing {}
48
+ err := command .Run (context )
48
49
NoError (t , err )
49
50
50
51
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 ))
52
54
}
53
55
54
- func TestCreateBuildPathIfEmpty (t * testing.T ) {
56
+ func TestGenerateBuildPathIfEmpty (t * testing.T ) {
55
57
context := make (map [string ]interface {})
56
58
57
59
context [constants .CTX_SKETCH_LOCATION ] = "test"
58
60
context [constants .CTX_BUILD_PATH ] = constants .EMPTY_STRING
59
61
60
- createBuildPathIfMissing := builder.CreateBuildPathIfMissing {}
62
+ createBuildPathIfMissing := builder.GenerateBuildPathIfMissing {}
61
63
err := createBuildPathIfMissing .Run (context )
62
64
NoError (t , err )
63
65
64
66
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 ))
66
69
}
67
70
68
- func TestDontCreateBuildPathIfPresent (t * testing.T ) {
71
+ func TestDontGenerateBuildPathIfPresent (t * testing.T ) {
69
72
context := make (map [string ]interface {})
70
73
71
74
context [constants .CTX_BUILD_PATH ] = "test"
72
75
73
- createBuildPathIfMissing := builder.CreateBuildPathIfMissing {}
76
+ createBuildPathIfMissing := builder.GenerateBuildPathIfMissing {}
74
77
err := createBuildPathIfMissing .Run (context )
75
78
NoError (t , err )
76
79
77
80
require .Equal (t , "test" , context [constants .CTX_BUILD_PATH ])
78
81
}
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