作者:ricklo
项目:arduino-builde
func TestLoadSketch(t *testing.T) {
context := make(map[string]interface{})
context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino")
loggerCommand := builder.SetupHumanLoggerIfMissing{}
err := loggerCommand.Run(context)
NoError(t, err)
loader := builder.SketchLoader{}
err = loader.Run(context)
NoError(t, err)
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
require.NotNil(t, sketch)
require.True(t, strings.Index(sketch.MainFile.Name, "sketch.ino") != -1)
require.Equal(t, 2, len(sketch.OtherSketchFiles))
require.True(t, strings.Index(sketch.OtherSketchFiles[0].Name, "old.pde") != -1)
require.True(t, strings.Index(sketch.OtherSketchFiles[1].Name, "other.ino") != -1)
require.Equal(t, 2, len(sketch.AdditionalFiles))
require.True(t, strings.Index(sketch.AdditionalFiles[0].Name, "header.h") != -1)
require.True(t, strings.Index(sketch.AdditionalFiles[1].Name, "helper.h") != -1)
}
作者:stevemarpl
项目:arduino-builde
func TestFailToLoadSketchFromFolder(t *testing.T) {
context := make(map[string]interface{})
context[constants.CTX_SKETCH_LOCATION] = "./sketch1"
loggerCommand := builder.SetupHumanLoggerIfMissing{}
err := loggerCommand.Run(context)
NoError(t, err)
loader := builder.SketchLoader{}
err = loader.Run(context)
require.Error(t, err)
sketch := context[constants.CTX_SKETCH]
require.Nil(t, sketch)
}
作者:stevemarpl
项目:arduino-builde
func TestLoadSketchNonExistentPath(t *testing.T) {
context := make(map[string]interface{})
context[constants.CTX_SKETCH_LOCATION] = "asdasd78128123981723981273asdasd"
loggerCommand := builder.SetupHumanLoggerIfMissing{}
err := loggerCommand.Run(context)
NoError(t, err)
loader := builder.SketchLoader{}
err = loader.Run(context)
require.Error(t, err)
sketch := context[constants.CTX_SKETCH]
require.Nil(t, sketch)
}
作者:ricklo
项目:arduino-builde
func TestLoadSketchFromFolder(t *testing.T) {
context := make(map[string]interface{})
context[constants.CTX_SKETCH_LOCATION] = "sketch_with_subfolders"
loggerCommand := builder.SetupHumanLoggerIfMissing{}
err := loggerCommand.Run(context)
NoError(t, err)
loader := builder.SketchLoader{}
err = loader.Run(context)
NoError(t, err)
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
require.NotNil(t, sketch)
require.True(t, strings.Index(sketch.MainFile.Name, "sketch_with_subfolders.ino") != -1)
require.Equal(t, 1, len(sketch.AdditionalFiles))
require.True(t, strings.Index(sketch.AdditionalFiles[0].Name, "other.cpp") != -1)
}