diff --git a/v2/cli-wrapper/arduino-cli_test.go b/v2/cli-wrapper/arduino-cli_test.go index 013ed40..dc9b315 100644 --- a/v2/cli-wrapper/arduino-cli_test.go +++ b/v2/cli-wrapper/arduino-cli_test.go @@ -176,7 +176,7 @@ func TestArduinoCli(t *testing.T) { req := &rpc.PlatformSearchRequest{ Instance: rpcInst, - AllVersions: true, + AllVersions: false, SearchArgs: "arduino:avr", } diff --git a/v2/cli-wrapper/cli-wrapper.go b/v2/cli-wrapper/cli-wrapper.go index 3c171bf..0f24c16 100644 --- a/v2/cli-wrapper/cli-wrapper.go +++ b/v2/cli-wrapper/cli-wrapper.go @@ -189,7 +189,7 @@ func (w *Wrapper) SearchPlatforms() ([]*rpc.Platform, error) { req := &rpc.PlatformSearchRequest{ Instance: inst, - AllVersions: true, + AllVersions: false, } resp, err := w.cli.PlatformSearch(req) diff --git a/v2/cli-wrapper/cli-wrapper_test.go b/v2/cli-wrapper/cli-wrapper_test.go index ec97568..aa481f7 100644 --- a/v2/cli-wrapper/cli-wrapper_test.go +++ b/v2/cli-wrapper/cli-wrapper_test.go @@ -183,7 +183,7 @@ func TestCliWrapperTest(t *testing.T) { searchReq := &rpc.PlatformSearchRequest{ Instance: inst, - AllVersions: true, + AllVersions: false, } expectedResp := &rpc.PlatformSearchResponse{ diff --git a/v2/commands/attach_and_watch_test.go b/v2/commands/attach_and_watch_test.go index cabb8ca..61c0f81 100644 --- a/v2/commands/attach_and_watch_test.go +++ b/v2/commands/attach_and_watch_test.go @@ -181,4 +181,10 @@ func TestAttachAndWatchCommand(t *testing.T) { err := env.Execute(args) assert.Error(env.T, err) }) + + testutil.RunMockIntegrationTest("errors if project not initialized", t, func(env *testutil.MockIntegrationTestEnv) { + args := []string{"attach-and-watch"} + err := env.Execute(args) + assert.Error(env.T, err) + }) } diff --git a/v2/commands/list_test.go b/v2/commands/list_test.go index 061c69a..cfecb32 100644 --- a/v2/commands/list_test.go +++ b/v2/commands/list_test.go @@ -69,7 +69,7 @@ func TestListBoardInfoCommands(t *testing.T) { platformReq := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } board := &rpc.Board{ diff --git a/v2/commands/search_test.go b/v2/commands/search_test.go index 409a952..2bbb1f3 100644 --- a/v2/commands/search_test.go +++ b/v2/commands/search_test.go @@ -125,7 +125,7 @@ func TestSearchPlatformCommand(t *testing.T) { searchReq := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } searchResp := &rpc.PlatformSearchResponse{ @@ -150,7 +150,7 @@ func TestSearchPlatformCommand(t *testing.T) { env.RunProjectInit() searchReq := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } dummyErr := errors.New("dummy error") diff --git a/v2/commands/upload_test.go b/v2/commands/upload_test.go index 07ad1cb..351a897 100644 --- a/v2/commands/upload_test.go +++ b/v2/commands/upload_test.go @@ -208,4 +208,10 @@ func TestUploadCommand(t *testing.T) { err := env.Execute(args) assert.Error(env.T, err) }) + + testutil.RunMockIntegrationTest("errors if project not initialized", t, func(env *testutil.MockIntegrationTestEnv) { + args := []string{"upload", buildName, "--attach"} + err := env.Execute(args) + assert.Error(env.T, err) + }) } diff --git a/v2/core/board_test.go b/v2/core/board_test.go index d578f15..3100b12 100644 --- a/v2/core/board_test.go +++ b/v2/core/board_test.go @@ -276,7 +276,7 @@ func TestBoardCore(t *testing.T) { instance := &rpc.Instance{Id: int32(1)} req := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } resp := &rpc.PlatformSearchResponse{SearchOutput: platforms} @@ -298,7 +298,7 @@ func TestBoardCore(t *testing.T) { instance := &rpc.Instance{Id: int32(1)} req := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } var resp *rpc.PlatformSearchResponse @@ -319,7 +319,7 @@ func TestBoardCore(t *testing.T) { instance := &rpc.Instance{Id: int32(1)} req := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } resp := &rpc.PlatformSearchResponse{SearchOutput: platforms} @@ -341,7 +341,7 @@ func TestBoardCore(t *testing.T) { instance := &rpc.Instance{Id: int32(1)} req := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } var resp *rpc.PlatformSearchResponse diff --git a/v2/core/file_watcher.go b/v2/core/file_watcher.go index ecf5981..7306254 100644 --- a/v2/core/file_watcher.go +++ b/v2/core/file_watcher.go @@ -36,9 +36,9 @@ func NewFileWatcher(file string, logger *log.Logger) (*FileWatcher, error) { return &FileWatcher{ file: file, watcher: watcher, - stop: make(chan bool, 1), - close: make(chan bool, 1), - restart: make(chan bool, 1), + stop: make(chan bool), + close: make(chan bool), + restart: make(chan bool), listeners: []Listener{}, logger: logger, }, nil @@ -85,7 +85,7 @@ func (f *FileWatcher) Watch() error { if removeEvt { if err := f.watcher.Add(f.file); err != nil { f.logger.WithError(err).Error("file watcher error") - f.close <- true + f.Close() return } } @@ -95,13 +95,13 @@ func (f *FileWatcher) Watch() error { } case err := <-f.watcher.Errors: f.logger.WithError(err).Error("Watch error") - f.close <- true + f.Close() return } } }() - // Block and wait for requests + // Block and wait for signals for { select { case <-f.stop: @@ -120,6 +120,7 @@ func (f *FileWatcher) Watch() error { f.watcher.Close() f.watcher = nil } + f.close <- true return nil } } diff --git a/v2/core/platform_test.go b/v2/core/platform_test.go index 61c9944..063a1ed 100644 --- a/v2/core/platform_test.go +++ b/v2/core/platform_test.go @@ -53,7 +53,7 @@ func TestPlatformCore(t *testing.T) { instance := &rpc.Instance{Id: int32(1)} req := &rpc.PlatformSearchRequest{ Instance: instance, - AllVersions: true, + AllVersions: false, } resp := &rpc.PlatformSearchResponse{ SearchOutput: platforms, diff --git a/v2/core/serial_test.go b/v2/core/serial_test.go index 8749204..dbe7fdb 100644 --- a/v2/core/serial_test.go +++ b/v2/core/serial_test.go @@ -64,4 +64,42 @@ func TestSerialPort(t *testing.T) { port.Close() assert.False(st, port.Streaming()) }) + + t.Run("errors if device isn't set", func(st *testing.T) { + device := "" + baud := 9600 + logger := logrus.New() + b := new(bytes.Buffer) + + logger.SetOutput(b) + port := core.NewArdiSerialPort(logger) + port.SetTargets(device, baud) + + st.Cleanup(func() { + port.Close() + port = nil + }) + + err := port.Watch() + assert.Error(st, err) + }) + + t.Run("errors if baud isn't set", func(st *testing.T) { + device := getPort() + baud := 0 + logger := logrus.New() + b := new(bytes.Buffer) + + logger.SetOutput(b) + port := core.NewArdiSerialPort(logger) + port.SetTargets(device, baud) + + st.Cleanup(func() { + port.Close() + port = nil + }) + + err := port.Watch() + assert.Error(st, err) + }) } diff --git a/v2/test_projects/pixie/pixie.ino b/v2/test_projects/pixie/pixie.ino index 3b27ad1..a65284a 100644 --- a/v2/test_projects/pixie/pixie.ino +++ b/v2/test_projects/pixie/pixie.ino @@ -11,7 +11,7 @@ #include "Adafruit_Pixie.h" #define NUMPIXELS 3 // Number of Pixies in the strip -#define PIXIEPIN 6 // Pin number for SoftwareSerial output +#define PIXIEPIN 6 // Pin number for SoftwareSerial output SoftwareSerial pixieSerial(-1, PIXIEPIN); @@ -19,7 +19,8 @@ Adafruit_Pixie strip = Adafruit_Pixie(NUMPIXELS, &pixieSerial); // Alternately, can use a hardware serial port for output, e.g.: // Adafruit_Pixie strip = Adafruit_Pixie(NUMPIXELS, &Serial1); -void setup() { +void setup() +{ int i; Serial.begin(9600); @@ -28,39 +29,42 @@ void setup() { pixieSerial.begin(115200); // Pixie REQUIRES this baud rate // Serial1.begin(115200); // <- Alt. if using hardware serial port - strip.setBrightness(200); // Adjust as necessary to avoid blinding + strip.setBrightness(200); // Adjust as necessary to avoid blinding Serial.println("Red"); - for(i=0; i< NUMPIXELS; i++) + for (i = 0; i < NUMPIXELS; i++) strip.setPixelColor(i, 255, 0, 0); strip.show(); delay(300); Serial.println("Green"); - for(i=0; i< NUMPIXELS; i++) + for (i = 0; i < NUMPIXELS; i++) strip.setPixelColor(i, 0, 255, 0); strip.show(); delay(300); Serial.println("Blue"); - for(i=0; i< NUMPIXELS; i++) + for (i = 0; i < NUMPIXELS; i++) strip.setPixelColor(i, 0, 0, 255); strip.show(); delay(300); } -void loop() { +void loop() +{ Serial.println("Rainbow"); rainbowCycle(10); } - // Slightly different, this makes the rainbow equally distributed throughout -void rainbowCycle(uint8_t wait) { +void rainbowCycle(uint8_t wait) +{ uint16_t i, j; - for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel - for(i=0; i< NUMPIXELS; i++) { + for (j = 0; j < 256 * 5; j++) + { // 5 cycles of all colors on wheel + for (i = 0; i < NUMPIXELS; i++) + { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); @@ -68,17 +72,22 @@ void rainbowCycle(uint8_t wait) { } } - // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. -uint32_t Wheel(byte WheelPos) { - if(WheelPos < 85) { - return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); - } else if(WheelPos < 170) { - WheelPos -= 85; - return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); - } else { - WheelPos -= 170; - return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); +uint32_t Wheel(byte WheelPos) +{ + if (WheelPos < 85) + { + return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); + } + else if (WheelPos < 170) + { + WheelPos -= 85; + return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); + } + else + { + WheelPos -= 170; + return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } }