Skip to content

Commit ffe8a23

Browse files
committed
Automatically create sketchbook directory on 'sketch new' command
Fix #40
1 parent a1877b6 commit ffe8a23

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

commands/commands_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ func makeTempSketchbookDir(t *testing.T) func() {
137137
require.NoError(t, err, "making temporary staging dir")
138138
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp.String())
139139
currSketchbookDir = tmp
140+
err = tmp.RemoveAll() // To test if the sketchbook dir is automatically created
141+
require.NoError(t, err)
142+
140143
fmt.Printf("ARDUINO_SKETCHBOOK_DIR = %s\n", os.Getenv("ARDUINO_SKETCHBOOK_DIR"))
141144
return func() {
142145
os.Unsetenv("ARDUINO_SKETCHBOOK_DIR")
@@ -212,6 +215,16 @@ func TestUserLibs(t *testing.T) {
212215
require.Contains(t, string(d), "MyLibWithWrongVersion")
213216
}
214217

218+
func TestSketchCommands(t *testing.T) {
219+
defer makeTempDataDir(t)()
220+
defer makeTempSketchbookDir(t)()
221+
//var d []byte
222+
var exitCode int
223+
224+
exitCode, _ = executeWithArgs(t, "sketch", "new", "Test")
225+
require.Zero(t, exitCode, "exit code")
226+
}
227+
215228
func TestLibDownloadAndInstall(t *testing.T) {
216229
defer makeTempDataDir(t)()
217230
defer makeTempSketchbookDir(t)()

commands/sketch/new.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void loop() {
4747

4848
func runNewCommand(cmd *cobra.Command, args []string) {
4949
sketchDir := commands.Config.SketchbookDir.Join(args[0])
50-
if err := sketchDir.Mkdir(); err != nil {
50+
if err := sketchDir.MkdirAll(); err != nil {
5151
formatter.PrintError(err, "Could not create sketch directory.")
5252
os.Exit(commands.ErrGeneric)
5353
}

0 commit comments

Comments
 (0)