Refactoring tests

Tests are now moved in the source folder.
Simplified travis-ci script.
Added some examples (that are checked for build, but not executed)
This commit is contained in:
Cristian Maglie
2016-01-01 18:26:21 +01:00
parent 2cc88585f9
commit 59b4222e7d
3 changed files with 43 additions and 42 deletions

View File

@@ -1,7 +1,9 @@
language: go language: go
go: go:
- 1.4 - 1.4.2
go_import_path: go.bug.st/serial
env: env:
- TEST_OS=linux TEST_ARCH=386 - TEST_OS=linux TEST_ARCH=386
@@ -20,18 +22,12 @@ matrix:
- env: TEST_OS=dragonfly TEST_ARCH=amd64 - env: TEST_OS=dragonfly TEST_ARCH=amd64
before_install: before_install:
- cd $GOROOT/src # bootstrap go tools for the specific OS/Arch
- GOOS=$TEST_OS GOARCH=$TEST_ARCH ./make.bash - ( cd $GOROOT/src; GOOS=$TEST_OS GOARCH=$TEST_ARCH ./make.bash )
- mkdir -p $HOME/gopath/src/go.bug.st
- mv $TRAVIS_BUILD_DIR $HOME/gopath/src/go.bug.st/serial
- export TRAVIS_BUILD_DIR=$HOME/gopath/src/go.bug.st/serial
- cd $TRAVIS_BUILD_DIR
install:
- export PATH="$HOME/gopath/bin:$PATH"
script: script:
- GOARM=5 GO386=387 GOOS=$TEST_OS GOARCH=$TEST_ARCH go build travis/build_check.go - GOARM=5 GO386=387 GOOS=$TEST_OS GOARCH=$TEST_ARCH go build -v ./...
- GOARM=5 GO386=387 GOOS=$TEST_OS GOARCH=$TEST_ARCH go test -c -v ./...
notifications: notifications:
email: email:

View File

@@ -1,16 +1,47 @@
// //
// Copyright 2014 Cristian Maglie. All rights reserved. // Copyright 2015 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// //
package serial package serial_test
import "go.bug.st/serial"
import "fmt" import "fmt"
import "log" import "log"
import "go.bug.st/serial"
func ExampleCommunication() { func ExampleGetPortsList() {
ports, err := serial.GetPortsList()
if err != nil {
log.Fatal(err)
}
if len(ports) == 0 {
fmt.Println("No serial ports found!")
} else {
for _, port := range ports {
fmt.Printf("Found port: %v\n", port)
}
}
}
func ExampleSetMode() {
port, err := serial.OpenPort("/dev/ttyACM0", &serial.Mode{})
if err != nil {
log.Fatal(err)
}
mode := &serial.Mode{
BaudRate: 9600,
Parity: serial.PARITY_NONE,
DataBits: 8,
StopBits: serial.STOPBITS_ONE,
}
if err := port.SetMode(mode); err != nil {
log.Fatal(err)
}
fmt.Println("Port set to 9600 N81")
}
func ExampleFullCommunication() {
ports, err := serial.GetPortsList() ports, err := serial.GetPortsList()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -41,6 +72,7 @@ func ExampleCommunication() {
buff := make([]byte, 100) buff := make([]byte, 100)
for { for {
// Reads up to 100 bytes
n, err := port.Read(buff) n, err := port.Read(buff)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -1,27 +0,0 @@
//
// Copyright 2014 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package test
import "go.bug.st/serial"
func BuildTest() {
serial.GetPortsList()
mode := &serial.Mode{
BaudRate: 9600,
Parity: serial.PARITY_NONE,
DataBits: 8,
StopBits: serial.STOPBITS_ONE,
}
port, _ := serial.OpenPort("", mode)
port.SetMode(mode)
buff := make([]byte, 100)
port.Write(buff)
port.Read(buff)
port.Close()
}
// vi:ts=2