mirror of
https://github.com/wahyd4/forego.git
synced 2026-08-09 05:07:05 +10:00
Use Go 1.6 vendoring (#80)
This commit is contained in:
committed by
David Dollar
parent
c69a0e4a4a
commit
9bc72ddb1f
@@ -8,9 +8,5 @@ env:
|
||||
global:
|
||||
- PATH=$HOME/gopath/bin:$PATH
|
||||
|
||||
before_install:
|
||||
- go get github.com/tools/godep
|
||||
- godep restore
|
||||
|
||||
script:
|
||||
- make test
|
||||
|
||||
Generated
+4
-6
@@ -1,9 +1,7 @@
|
||||
{
|
||||
"ImportPath": "github.com/ddollar/forego",
|
||||
"GoVersion": "go1.4.1",
|
||||
"Packages": [
|
||||
"."
|
||||
],
|
||||
"GoVersion": "go1.6",
|
||||
"GodepVersion": "v60",
|
||||
"Deps": [
|
||||
{
|
||||
"ImportPath": "bitbucket.org/kardianos/osext",
|
||||
@@ -16,8 +14,8 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/ddollar/dist",
|
||||
"Comment": "v0.2.0-3-gd4be91e",
|
||||
"Rev": "d4be91e0cd1771c51ae117e18eb6c379757623f4"
|
||||
"Comment": "v0.2.0-2-gf559761",
|
||||
"Rev": "f559761fd36c52dc90d7d2c0bc537e6d96b0edc5"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/ddollar/go-update",
|
||||
|
||||
Generated
-2
@@ -1,2 +0,0 @@
|
||||
/pkg
|
||||
/bin
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build darwin linux freebsd netbsd windows
|
||||
|
||||
package osext
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
oexec "os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const execPath_EnvVar = "OSTEST_OUTPUT_EXECPATH"
|
||||
|
||||
func TestExecPath(t *testing.T) {
|
||||
ep, err := Executable()
|
||||
if err != nil {
|
||||
t.Fatalf("ExecPath failed: %v", err)
|
||||
}
|
||||
// we want fn to be of the form "dir/prog"
|
||||
dir := filepath.Dir(filepath.Dir(ep))
|
||||
fn, err := filepath.Rel(dir, ep)
|
||||
if err != nil {
|
||||
t.Fatalf("filepath.Rel: %v", err)
|
||||
}
|
||||
cmd := &oexec.Cmd{}
|
||||
// make child start with a relative program path
|
||||
cmd.Dir = dir
|
||||
cmd.Path = fn
|
||||
// forge argv[0] for child, so that we can verify we could correctly
|
||||
// get real path of the executable without influenced by argv[0].
|
||||
cmd.Args = []string{"-", "-test.run=XXXX"}
|
||||
cmd.Env = []string{fmt.Sprintf("%s=1", execPath_EnvVar)}
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("exec(self) failed: %v", err)
|
||||
}
|
||||
outs := string(out)
|
||||
if !filepath.IsAbs(outs) {
|
||||
t.Fatalf("Child returned %q, want an absolute path", out)
|
||||
}
|
||||
if !sameFile(outs, ep) {
|
||||
t.Fatalf("Child returned %q, not the same file as %q", out, ep)
|
||||
}
|
||||
}
|
||||
|
||||
func sameFile(fn1, fn2 string) bool {
|
||||
fi1, err := os.Stat(fn1)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
fi2, err := os.Stat(fn2)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return os.SameFile(fi1, fi2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
if e := os.Getenv(execPath_EnvVar); e != "" {
|
||||
// first chdir to another path
|
||||
dir := "/"
|
||||
if runtime.GOOS == "windows" {
|
||||
dir = filepath.VolumeName(".")
|
||||
}
|
||||
os.Chdir(dir)
|
||||
if ep, err := Executable(); err != nil {
|
||||
fmt.Fprint(os.Stderr, "ERROR: ", err)
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, ep)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package ct
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChangeColor(t *testing.T) {
|
||||
defer ResetColor()
|
||||
fmt.Println("Normal text...")
|
||||
text := "This is an demo of using ChangeColor to output colorful texts"
|
||||
i := 1
|
||||
for _, c := range text {
|
||||
ChangeColor(Color(i/2%8)+Black, i%2 == 1, Color((i+2)/2%8)+Black, false)
|
||||
fmt.Print(string(c))
|
||||
i++
|
||||
} // for c
|
||||
fmt.Println()
|
||||
ChangeColor(Red, true, White, false)
|
||||
fmt.Println("Before reset.")
|
||||
ChangeColor(Red, false, White, true)
|
||||
fmt.Println("Before reset.")
|
||||
ResetColor()
|
||||
fmt.Println("After reset.")
|
||||
fmt.Println("After reset.")
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"ImportPath": "github.com/ddollar/dist",
|
||||
"GoVersion": "go1.4.1",
|
||||
"Packages": [
|
||||
"."
|
||||
],
|
||||
"Deps": [
|
||||
{
|
||||
"ImportPath": "bitbucket.org/kardianos/osext",
|
||||
"Comment": "null-13",
|
||||
"Rev": "5d3ddcf53a508cc2f7404eaebf546ef2cb5cdb6e"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/ddollar/go-update",
|
||||
"Rev": "4733469d35539f410e0e84552944fa0df7e72c98"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/kr/binarydist",
|
||||
"Rev": "9955b0ab8708602d411341e55fffd7e0700f86bd"
|
||||
}
|
||||
]
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
This directory tree is generated automatically by godep.
|
||||
|
||||
Please do not edit.
|
||||
|
||||
See https://github.com/tools/godep for more information.
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
package binarydist
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func mustOpen(path string) *os.File {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func mustReadAll(r io.Reader) []byte {
|
||||
b, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func fileCmp(a, b *os.File) int64 {
|
||||
sa, err := a.Seek(0, 2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
sb, err := b.Seek(0, 2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if sa != sb {
|
||||
return sa
|
||||
}
|
||||
|
||||
_, err = a.Seek(0, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = b.Seek(0, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pa, err := ioutil.ReadAll(a)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pb, err := ioutil.ReadAll(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for i := range pa {
|
||||
if pa[i] != pb[i] {
|
||||
return int64(i)
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func mustWriteRandFile(path string, size int) *os.File {
|
||||
p := make([]byte, size)
|
||||
_, err := rand.Read(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = f.Write(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = f.Seek(0, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
package binarydist
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var diffT = []struct {
|
||||
old *os.File
|
||||
new *os.File
|
||||
}{
|
||||
{
|
||||
old: mustWriteRandFile("test.old", 1e3),
|
||||
new: mustWriteRandFile("test.new", 1e3),
|
||||
},
|
||||
{
|
||||
old: mustOpen("testdata/sample.old"),
|
||||
new: mustOpen("testdata/sample.new"),
|
||||
},
|
||||
}
|
||||
|
||||
func TestDiff(t *testing.T) {
|
||||
for _, s := range diffT {
|
||||
got, err := ioutil.TempFile("/tmp", "bspatch.")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.Remove(got.Name())
|
||||
|
||||
exp, err := ioutil.TempFile("/tmp", "bspatch.")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cmd := exec.Command("bsdiff", s.old.Name(), s.new.Name(), exp.Name())
|
||||
cmd.Stdout = os.Stdout
|
||||
err = cmd.Run()
|
||||
os.Remove(exp.Name())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = Diff(s.old, s.new, got)
|
||||
if err != nil {
|
||||
t.Fatal("err", err)
|
||||
}
|
||||
|
||||
_, err = got.Seek(0, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
gotBuf := mustReadAll(got)
|
||||
expBuf := mustReadAll(exp)
|
||||
|
||||
if !bytes.Equal(gotBuf, expBuf) {
|
||||
t.Fail()
|
||||
t.Logf("diff %s %s", s.old.Name(), s.new.Name())
|
||||
t.Logf("%s: len(got) = %d", got.Name(), len(gotBuf))
|
||||
t.Logf("%s: len(exp) = %d", exp.Name(), len(expBuf))
|
||||
i := matchlen(gotBuf, expBuf)
|
||||
t.Logf("produced different output at pos %d; %d != %d", i, gotBuf[i], expBuf[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package binarydist
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPatch(t *testing.T) {
|
||||
mustWriteRandFile("test.old", 1e3)
|
||||
mustWriteRandFile("test.new", 1e3)
|
||||
|
||||
got, err := ioutil.TempFile("/tmp", "bspatch.")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.Remove(got.Name())
|
||||
|
||||
err = exec.Command("bsdiff", "test.old", "test.new", "test.patch").Run()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = Patch(mustOpen("test.old"), got, mustOpen("test.patch"))
|
||||
if err != nil {
|
||||
t.Fatal("err", err)
|
||||
}
|
||||
|
||||
ref, err := got.Seek(0, 2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
t.Logf("got %d bytes", ref)
|
||||
if n := fileCmp(got, mustOpen("test.new")); n > -1 {
|
||||
t.Fatalf("produced different output at pos %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatchHk(t *testing.T) {
|
||||
got, err := ioutil.TempFile("/tmp", "bspatch.")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.Remove(got.Name())
|
||||
|
||||
err = Patch(mustOpen("testdata/sample.old"), got, mustOpen("testdata/sample.patch"))
|
||||
if err != nil {
|
||||
t.Fatal("err", err)
|
||||
}
|
||||
|
||||
ref, err := got.Seek(0, 2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
t.Logf("got %d bytes", ref)
|
||||
if n := fileCmp(got, mustOpen("testdata/sample.new")); n > -1 {
|
||||
t.Fatalf("produced different output at pos %d", n)
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package binarydist
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var sortT = [][]byte{
|
||||
mustRandBytes(1000),
|
||||
mustReadAll(mustOpen("test.old")),
|
||||
[]byte("abcdefabcdef"),
|
||||
}
|
||||
|
||||
func TestQsufsort(t *testing.T) {
|
||||
for _, s := range sortT {
|
||||
I := qsufsort(s)
|
||||
for i := 1; i < len(I); i++ {
|
||||
if bytes.Compare(s[I[i-1]:], s[I[i]:]) > 0 {
|
||||
t.Fatalf("unsorted at %d", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mustRandBytes(n int) []byte {
|
||||
b := make([]byte, n)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
-73
@@ -1,73 +0,0 @@
|
||||
package pretty
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type difftest struct {
|
||||
a interface{}
|
||||
b interface{}
|
||||
exp []string
|
||||
}
|
||||
|
||||
type S struct {
|
||||
A int
|
||||
S *S
|
||||
I interface{}
|
||||
C []int
|
||||
}
|
||||
|
||||
var diffs = []difftest{
|
||||
{a: nil, b: nil},
|
||||
{a: S{A: 1}, b: S{A: 1}},
|
||||
|
||||
{0, "", []string{`int != string`}},
|
||||
{0, 1, []string{`0 != 1`}},
|
||||
{S{}, new(S), []string{`pretty.S != *pretty.S`}},
|
||||
{"a", "b", []string{`"a" != "b"`}},
|
||||
{S{}, S{A: 1}, []string{`A: 0 != 1`}},
|
||||
{new(S), &S{A: 1}, []string{`A: 0 != 1`}},
|
||||
{S{S: new(S)}, S{S: &S{A: 1}}, []string{`S.A: 0 != 1`}},
|
||||
{S{}, S{I: 0}, []string{`I: nil != 0`}},
|
||||
{S{I: 1}, S{I: "x"}, []string{`I: int != string`}},
|
||||
{S{}, S{C: []int{1}}, []string{`C: []int(nil) != []int{1}`}},
|
||||
{S{C: []int{}}, S{C: []int{1}}, []string{`C: []int{} != []int{1}`}},
|
||||
{S{}, S{A: 1, S: new(S)}, []string{`A: 0 != 1`, `S: nil != &{0 <nil> <nil> []}`}},
|
||||
}
|
||||
|
||||
func TestDiff(t *testing.T) {
|
||||
for _, tt := range diffs {
|
||||
got := Diff(tt.a, tt.b)
|
||||
eq := len(got) == len(tt.exp)
|
||||
if eq {
|
||||
for i := range got {
|
||||
eq = eq && got[i] == tt.exp[i]
|
||||
}
|
||||
}
|
||||
if !eq {
|
||||
t.Errorf("diffing % #v", tt.a)
|
||||
t.Errorf("with % #v", tt.b)
|
||||
diffdiff(t, got, tt.exp)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func diffdiff(t *testing.T, got, exp []string) {
|
||||
minus(t, "unexpected:", got, exp)
|
||||
minus(t, "missing:", exp, got)
|
||||
}
|
||||
|
||||
func minus(t *testing.T, s string, a, b []string) {
|
||||
var i, j int
|
||||
for i = 0; i < len(a); i++ {
|
||||
for j = 0; j < len(b); j++ {
|
||||
if a[i] == b[j] {
|
||||
break
|
||||
}
|
||||
}
|
||||
if j == len(b) {
|
||||
t.Error(s, a[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package pretty_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/kr/pretty"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
type myType struct {
|
||||
a, b int
|
||||
}
|
||||
var x = []myType{{1, 2}, {3, 4}, {5, 6}}
|
||||
fmt.Printf("%# v", pretty.Formatter(x))
|
||||
// output:
|
||||
// []pretty_test.myType{
|
||||
// {a:1, b:2},
|
||||
// {a:3, b:4},
|
||||
// {a:5, b:6},
|
||||
// }
|
||||
}
|
||||
-146
@@ -1,146 +0,0 @@
|
||||
package pretty
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type test struct {
|
||||
v interface{}
|
||||
s string
|
||||
}
|
||||
|
||||
type LongStructTypeName struct {
|
||||
longFieldName interface{}
|
||||
otherLongFieldName interface{}
|
||||
}
|
||||
|
||||
type SA struct {
|
||||
t *T
|
||||
}
|
||||
|
||||
type T struct {
|
||||
x, y int
|
||||
}
|
||||
|
||||
type F int
|
||||
|
||||
func (f F) Format(s fmt.State, c rune) {
|
||||
fmt.Fprintf(s, "F(%d)", int(f))
|
||||
}
|
||||
|
||||
var long = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
var gosyntax = []test{
|
||||
{nil, `nil`},
|
||||
{"", `""`},
|
||||
{"a", `"a"`},
|
||||
{1, "int(1)"},
|
||||
{1.0, "float64(1)"},
|
||||
{[]int(nil), "[]int(nil)"},
|
||||
{[0]int{}, "[0]int{}"},
|
||||
{complex(1, 0), "(1+0i)"},
|
||||
//{make(chan int), "(chan int)(0x1234)"},
|
||||
{unsafe.Pointer(uintptr(1)), "unsafe.Pointer(0x1)"},
|
||||
{func(int) {}, "func(int) {...}"},
|
||||
{map[int]int{1: 1}, "map[int]int{1:1}"},
|
||||
{int32(1), "int32(1)"},
|
||||
{io.EOF, `&errors.errorString{s:"EOF"}`},
|
||||
{[]string{"a"}, `[]string{"a"}`},
|
||||
{
|
||||
[]string{long},
|
||||
`[]string{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"}`,
|
||||
},
|
||||
{F(5), "pretty.F(5)"},
|
||||
{
|
||||
SA{&T{1, 2}},
|
||||
`pretty.SA{
|
||||
t: &pretty.T{x:1, y:2},
|
||||
}`,
|
||||
},
|
||||
{
|
||||
map[int][]byte{1: []byte{}},
|
||||
`map[int][]uint8{
|
||||
1: {},
|
||||
}`,
|
||||
},
|
||||
{
|
||||
map[int]T{1: T{}},
|
||||
`map[int]pretty.T{
|
||||
1: {},
|
||||
}`,
|
||||
},
|
||||
{
|
||||
long,
|
||||
`"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"`,
|
||||
},
|
||||
{
|
||||
LongStructTypeName{
|
||||
longFieldName: LongStructTypeName{},
|
||||
otherLongFieldName: long,
|
||||
},
|
||||
`pretty.LongStructTypeName{
|
||||
longFieldName: pretty.LongStructTypeName{},
|
||||
otherLongFieldName: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||
}`,
|
||||
},
|
||||
{
|
||||
&LongStructTypeName{
|
||||
longFieldName: &LongStructTypeName{},
|
||||
otherLongFieldName: (*LongStructTypeName)(nil),
|
||||
},
|
||||
`&pretty.LongStructTypeName{
|
||||
longFieldName: &pretty.LongStructTypeName{},
|
||||
otherLongFieldName: (*pretty.LongStructTypeName)(nil),
|
||||
}`,
|
||||
},
|
||||
{
|
||||
[]LongStructTypeName{
|
||||
{nil, nil},
|
||||
{3, 3},
|
||||
{long, nil},
|
||||
},
|
||||
`[]pretty.LongStructTypeName{
|
||||
{},
|
||||
{
|
||||
longFieldName: int(3),
|
||||
otherLongFieldName: int(3),
|
||||
},
|
||||
{
|
||||
longFieldName: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||
otherLongFieldName: nil,
|
||||
},
|
||||
}`,
|
||||
},
|
||||
{
|
||||
[]interface{}{
|
||||
LongStructTypeName{nil, nil},
|
||||
[]byte{1, 2, 3},
|
||||
T{3, 4},
|
||||
LongStructTypeName{long, nil},
|
||||
},
|
||||
`[]interface {}{
|
||||
pretty.LongStructTypeName{},
|
||||
[]uint8{0x1, 0x2, 0x3},
|
||||
pretty.T{x:3, y:4},
|
||||
pretty.LongStructTypeName{
|
||||
longFieldName: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||
otherLongFieldName: nil,
|
||||
},
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
||||
func TestGoSyntax(t *testing.T) {
|
||||
for _, tt := range gosyntax {
|
||||
s := fmt.Sprintf("%# v", Formatter(tt.v))
|
||||
if tt.s != s {
|
||||
t.Errorf("expected %q", tt.s)
|
||||
t.Errorf("got %q", s)
|
||||
t.Errorf("expraw\n%s", tt.s)
|
||||
t.Errorf("gotraw\n%s", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
Package colwriter provides a write filter that formats
|
||||
input lines in multiple columns.
|
||||
|
||||
The package is a straightforward translation from
|
||||
/src/cmd/draw/mc.c in Plan 9 from User Space.
|
||||
-147
@@ -1,147 +0,0 @@
|
||||
// Package colwriter provides a write filter that formats
|
||||
// input lines in multiple columns.
|
||||
//
|
||||
// The package is a straightforward translation from
|
||||
// /src/cmd/draw/mc.c in Plan 9 from User Space.
|
||||
package colwriter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
tab = 4
|
||||
)
|
||||
|
||||
const (
|
||||
// Print each input line ending in a colon ':' separately.
|
||||
BreakOnColon uint = 1 << iota
|
||||
)
|
||||
|
||||
// A Writer is a filter that arranges input lines in as many columns as will
|
||||
// fit in its width. Tab '\t' chars in the input are translated to sequences
|
||||
// of spaces ending at multiples of 4 positions.
|
||||
//
|
||||
// If BreakOnColon is set, each input line ending in a colon ':' is written
|
||||
// separately.
|
||||
//
|
||||
// The Writer assumes that all Unicode code points have the same width; this
|
||||
// may not be true in some fonts.
|
||||
type Writer struct {
|
||||
w io.Writer
|
||||
buf []byte
|
||||
width int
|
||||
flag uint
|
||||
}
|
||||
|
||||
// NewWriter allocates and initializes a new Writer writing to w.
|
||||
// Parameter width controls the total number of characters on each line
|
||||
// across all columns.
|
||||
func NewWriter(w io.Writer, width int, flag uint) *Writer {
|
||||
return &Writer{
|
||||
w: w,
|
||||
width: width,
|
||||
flag: flag,
|
||||
}
|
||||
}
|
||||
|
||||
// Write writes p to the writer w. The only errors returned are ones
|
||||
// encountered while writing to the underlying output stream.
|
||||
func (w *Writer) Write(p []byte) (n int, err error) {
|
||||
var linelen int
|
||||
var lastWasColon bool
|
||||
for i, c := range p {
|
||||
w.buf = append(w.buf, c)
|
||||
linelen++
|
||||
if c == '\t' {
|
||||
w.buf[len(w.buf)-1] = ' '
|
||||
for linelen%tab != 0 {
|
||||
w.buf = append(w.buf, ' ')
|
||||
linelen++
|
||||
}
|
||||
}
|
||||
if w.flag&BreakOnColon != 0 && c == ':' {
|
||||
lastWasColon = true
|
||||
} else if lastWasColon {
|
||||
if c == '\n' {
|
||||
pos := bytes.LastIndex(w.buf[:len(w.buf)-1], []byte{'\n'})
|
||||
if pos < 0 {
|
||||
pos = 0
|
||||
}
|
||||
line := w.buf[pos:]
|
||||
w.buf = w.buf[:pos]
|
||||
if err = w.columnate(); err != nil {
|
||||
if len(line) < i {
|
||||
return i - len(line), err
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
if n, err := w.w.Write(line); err != nil {
|
||||
if r := len(line) - n; r < i {
|
||||
return i - r, err
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
lastWasColon = false
|
||||
}
|
||||
if c == '\n' {
|
||||
linelen = 0
|
||||
}
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// Flush should be called after the last call to Write to ensure that any data
|
||||
// buffered in the Writer is written to output.
|
||||
func (w *Writer) Flush() error {
|
||||
return w.columnate()
|
||||
}
|
||||
|
||||
func (w *Writer) columnate() error {
|
||||
words := bytes.Split(w.buf, []byte{'\n'})
|
||||
w.buf = nil
|
||||
if len(words[len(words)-1]) == 0 {
|
||||
words = words[:len(words)-1]
|
||||
}
|
||||
maxwidth := 0
|
||||
for _, wd := range words {
|
||||
if n := utf8.RuneCount(wd); n > maxwidth {
|
||||
maxwidth = n
|
||||
}
|
||||
}
|
||||
maxwidth++ // space char
|
||||
wordsPerLine := w.width / maxwidth
|
||||
if wordsPerLine <= 0 {
|
||||
wordsPerLine = 1
|
||||
}
|
||||
nlines := (len(words) + wordsPerLine - 1) / wordsPerLine
|
||||
for i := 0; i < nlines; i++ {
|
||||
col := 0
|
||||
endcol := 0
|
||||
for j := i; j < len(words); j += nlines {
|
||||
endcol += maxwidth
|
||||
_, err := w.w.Write(words[j])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
col += utf8.RuneCount(words[j])
|
||||
if j+nlines < len(words) {
|
||||
for col < endcol {
|
||||
_, err := w.w.Write([]byte{' '})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
col++
|
||||
}
|
||||
}
|
||||
}
|
||||
_, err := w.w.Write([]byte{'\n'})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
package colwriter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var src = `
|
||||
.git
|
||||
.gitignore
|
||||
.godir
|
||||
Procfile:
|
||||
README.md
|
||||
api.go
|
||||
apps.go
|
||||
auth.go
|
||||
darwin.go
|
||||
data.go
|
||||
dyno.go:
|
||||
env.go
|
||||
git.go
|
||||
help.go
|
||||
hkdist
|
||||
linux.go
|
||||
ls.go
|
||||
main.go
|
||||
plugin.go
|
||||
run.go
|
||||
scale.go
|
||||
ssh.go
|
||||
tail.go
|
||||
term
|
||||
unix.go
|
||||
update.go
|
||||
version.go
|
||||
windows.go
|
||||
`[1:]
|
||||
|
||||
var tests = []struct{
|
||||
wid int
|
||||
flag uint
|
||||
src string
|
||||
want string
|
||||
}{
|
||||
{80, 0, "", ""},
|
||||
{80, 0, src, `
|
||||
.git README.md darwin.go git.go ls.go scale.go unix.go
|
||||
.gitignore api.go data.go help.go main.go ssh.go update.go
|
||||
.godir apps.go dyno.go: hkdist plugin.go tail.go version.go
|
||||
Procfile: auth.go env.go linux.go run.go term windows.go
|
||||
`[1:]},
|
||||
{80, BreakOnColon, src, `
|
||||
.git .gitignore .godir
|
||||
|
||||
Procfile:
|
||||
README.md api.go apps.go auth.go darwin.go data.go
|
||||
|
||||
dyno.go:
|
||||
env.go hkdist main.go scale.go term version.go
|
||||
git.go linux.go plugin.go ssh.go unix.go windows.go
|
||||
help.go ls.go run.go tail.go update.go
|
||||
`[1:]},
|
||||
{20, 0, `
|
||||
Hello
|
||||
Γειά σου
|
||||
안녕
|
||||
今日は
|
||||
`[1:], `
|
||||
Hello 안녕
|
||||
Γειά σου 今日は
|
||||
`[1:]},
|
||||
}
|
||||
|
||||
func TestWriter(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
b := new(bytes.Buffer)
|
||||
w := NewWriter(b, test.wid, test.flag)
|
||||
if _, err := w.Write([]byte(test.src)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := w.Flush(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if g := b.String(); test.want != g {
|
||||
t.Log("\n" + test.want)
|
||||
t.Log("\n" + g)
|
||||
t.Errorf("%q != %q", test.want, g)
|
||||
}
|
||||
}
|
||||
}
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
package text
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type T struct {
|
||||
inp, exp, pre string
|
||||
}
|
||||
|
||||
var tests = []T{
|
||||
{
|
||||
"The quick brown fox\njumps over the lazy\ndog.\nBut not quickly.\n",
|
||||
"xxxThe quick brown fox\nxxxjumps over the lazy\nxxxdog.\nxxxBut not quickly.\n",
|
||||
"xxx",
|
||||
},
|
||||
{
|
||||
"The quick brown fox\njumps over the lazy\ndog.\n\nBut not quickly.",
|
||||
"xxxThe quick brown fox\nxxxjumps over the lazy\nxxxdog.\n\nxxxBut not quickly.",
|
||||
"xxx",
|
||||
},
|
||||
}
|
||||
|
||||
func TestIndent(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
got := Indent(test.inp, test.pre)
|
||||
if got != test.exp {
|
||||
t.Errorf("mismatch %q != %q", got, test.exp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type IndentWriterTest struct {
|
||||
inp, exp string
|
||||
pre []string
|
||||
}
|
||||
|
||||
var ts = []IndentWriterTest{
|
||||
{
|
||||
`
|
||||
The quick brown fox
|
||||
jumps over the lazy
|
||||
dog.
|
||||
But not quickly.
|
||||
`[1:],
|
||||
`
|
||||
xxxThe quick brown fox
|
||||
xxxjumps over the lazy
|
||||
xxxdog.
|
||||
xxxBut not quickly.
|
||||
`[1:],
|
||||
[]string{"xxx"},
|
||||
},
|
||||
{
|
||||
`
|
||||
The quick brown fox
|
||||
jumps over the lazy
|
||||
dog.
|
||||
But not quickly.
|
||||
`[1:],
|
||||
`
|
||||
xxaThe quick brown fox
|
||||
xxxjumps over the lazy
|
||||
xxxdog.
|
||||
xxxBut not quickly.
|
||||
`[1:],
|
||||
[]string{"xxa", "xxx"},
|
||||
},
|
||||
{
|
||||
`
|
||||
The quick brown fox
|
||||
jumps over the lazy
|
||||
dog.
|
||||
But not quickly.
|
||||
`[1:],
|
||||
`
|
||||
xxaThe quick brown fox
|
||||
xxbjumps over the lazy
|
||||
xxcdog.
|
||||
xxxBut not quickly.
|
||||
`[1:],
|
||||
[]string{"xxa", "xxb", "xxc", "xxx"},
|
||||
},
|
||||
{
|
||||
`
|
||||
The quick brown fox
|
||||
jumps over the lazy
|
||||
dog.
|
||||
|
||||
But not quickly.`[1:],
|
||||
`
|
||||
xxaThe quick brown fox
|
||||
xxxjumps over the lazy
|
||||
xxxdog.
|
||||
xxx
|
||||
xxxBut not quickly.`[1:],
|
||||
[]string{"xxa", "xxx"},
|
||||
},
|
||||
}
|
||||
|
||||
func TestIndentWriter(t *testing.T) {
|
||||
for _, test := range ts {
|
||||
b := new(bytes.Buffer)
|
||||
pre := make([][]byte, len(test.pre))
|
||||
for i := range test.pre {
|
||||
pre[i] = []byte(test.pre[i])
|
||||
}
|
||||
w := NewIndentWriter(b, pre...)
|
||||
if _, err := w.Write([]byte(test.inp)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if got := b.String(); got != test.exp {
|
||||
t.Errorf("mismatch %q != %q", got, test.exp)
|
||||
t.Log(got)
|
||||
t.Log(test.exp)
|
||||
}
|
||||
}
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
Command mc prints in multiple columns.
|
||||
|
||||
Usage: mc [-] [-N] [file...]
|
||||
|
||||
Mc splits the input into as many columns as will fit in N
|
||||
print positions. If the output is a tty, the default N is
|
||||
the number of characters in a terminal line; otherwise the
|
||||
default N is 80. Under option - each input line ending in
|
||||
a colon ':' is printed separately.
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
// Command mc prints in multiple columns.
|
||||
//
|
||||
// Usage: mc [-] [-N] [file...]
|
||||
//
|
||||
// Mc splits the input into as many columns as will fit in N
|
||||
// print positions. If the output is a tty, the default N is
|
||||
// the number of characters in a terminal line; otherwise the
|
||||
// default N is 80. Under option - each input line ending in
|
||||
// a colon ':' is printed separately.
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kr/pty"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/kr/text/colwriter"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var width int
|
||||
var flag uint
|
||||
args := os.Args[1:]
|
||||
for len(args) > 0 && len(args[0]) > 0 && args[0][0] == '-' {
|
||||
if len(args[0]) > 1 {
|
||||
width, _ = strconv.Atoi(args[0][1:])
|
||||
} else {
|
||||
flag |= colwriter.BreakOnColon
|
||||
}
|
||||
args = args[1:]
|
||||
}
|
||||
if width < 1 {
|
||||
_, width, _ = pty.Getsize(os.Stdout)
|
||||
}
|
||||
if width < 1 {
|
||||
width = 80
|
||||
}
|
||||
|
||||
w := colwriter.NewWriter(os.Stdout, width, flag)
|
||||
if len(args) > 0 {
|
||||
for _, s := range args {
|
||||
if f, err := os.Open(s); err == nil {
|
||||
copyin(w, f)
|
||||
f.Close()
|
||||
} else {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
copyin(w, os.Stdin)
|
||||
}
|
||||
}
|
||||
|
||||
func copyin(w *colwriter.Writer, r io.Reader) {
|
||||
if _, err := io.Copy(w, r); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if err := w.Flush(); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package text
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var text = "The quick brown fox jumps over the lazy dog."
|
||||
|
||||
func TestWrap(t *testing.T) {
|
||||
exp := [][]string{
|
||||
{"The", "quick", "brown", "fox"},
|
||||
{"jumps", "over", "the", "lazy", "dog."},
|
||||
}
|
||||
words := bytes.Split([]byte(text), sp)
|
||||
got := WrapWords(words, 1, 24, defaultPenalty)
|
||||
if len(exp) != len(got) {
|
||||
t.Fail()
|
||||
}
|
||||
for i := range exp {
|
||||
if len(exp[i]) != len(got[i]) {
|
||||
t.Fail()
|
||||
}
|
||||
for j := range exp[i] {
|
||||
if exp[i][j] != string(got[i][j]) {
|
||||
t.Fatal(i, exp[i][j], got[i][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapNarrow(t *testing.T) {
|
||||
exp := "The\nquick\nbrown\nfox\njumps\nover\nthe\nlazy\ndog."
|
||||
if Wrap(text, 5) != exp {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapOneLine(t *testing.T) {
|
||||
exp := "The quick brown fox jumps over the lazy dog."
|
||||
if Wrap(text, 500) != exp {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package gotenv_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/subosito/gotenv"
|
||||
)
|
||||
|
||||
func ExampleParse() {
|
||||
pairs := gotenv.Parse(strings.NewReader("FOO=test\nBAR=$FOO"))
|
||||
fmt.Printf("%+v\n", pairs) // gotenv.Env{"FOO": "test", "BAR": "test"}
|
||||
|
||||
pairs = gotenv.Parse(strings.NewReader(`FOO="bar"`))
|
||||
fmt.Printf("%+v\n", pairs) // gotenv.Env{"FOO": "bar"}
|
||||
}
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
export OPTION_A=2
|
||||
export OPTION_B='\n'
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
OPTION_A=1
|
||||
OPTION_B=2
|
||||
OPTION_C= 3
|
||||
OPTION_D =4
|
||||
OPTION_E = 5
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
OPTION_A='1'
|
||||
OPTION_B='2'
|
||||
OPTION_C=''
|
||||
OPTION_D='\n'
|
||||
OPTION_E="1"
|
||||
OPTION_F="2"
|
||||
OPTION_G=""
|
||||
OPTION_H="\n"
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
OPTION_A: 1
|
||||
OPTION_B: '2'
|
||||
OPTION_C: ''
|
||||
OPTION_D: '\n'
|
||||
-187
@@ -1,187 +0,0 @@
|
||||
package gotenv
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var formats = []struct {
|
||||
in string
|
||||
out Env
|
||||
preset bool
|
||||
}{
|
||||
// parses unquoted values
|
||||
{`FOO=bar`, Env{"FOO": "bar"}, false},
|
||||
|
||||
// parses values with spaces around equal sign
|
||||
{`FOO =bar`, Env{"FOO": "bar"}, false},
|
||||
{`FOO= bar`, Env{"FOO": "bar"}, false},
|
||||
|
||||
// parses double quoted values
|
||||
{`FOO="bar"`, Env{"FOO": "bar"}, false},
|
||||
|
||||
// parses single quoted values
|
||||
{`FOO='bar'`, Env{"FOO": "bar"}, false},
|
||||
|
||||
// parses escaped double quotes
|
||||
{`FOO="escaped\"bar"`, Env{"FOO": `escaped"bar`}, false},
|
||||
|
||||
// parses empty values
|
||||
{`FOO=`, Env{"FOO": ""}, false},
|
||||
|
||||
// expands variables found in values
|
||||
{"FOO=test\nBAR=$FOO", Env{"FOO": "test", "BAR": "test"}, false},
|
||||
|
||||
// parses variables wrapped in brackets
|
||||
{"FOO=test\nBAR=${FOO}bar", Env{"FOO": "test", "BAR": "testbar"}, false},
|
||||
|
||||
// reads variables from ENV when expanding if not found in local env
|
||||
{`BAR=$FOO`, Env{"BAR": "test"}, true},
|
||||
|
||||
// expands undefined variables to an empty string
|
||||
{`BAR=$FOO`, Env{"BAR": ""}, false},
|
||||
|
||||
// expands variables in quoted strings
|
||||
{"FOO=test\nBAR='quote $FOO'", Env{"FOO": "test", "BAR": "quote test"}, false},
|
||||
|
||||
// does not expand escaped variables
|
||||
{`FOO="foo\$BAR"`, Env{"FOO": "foo$BAR"}, false},
|
||||
{`FOO="foo\${BAR}"`, Env{"FOO": "foo${BAR}"}, false},
|
||||
|
||||
// parses yaml style options
|
||||
{"OPTION_A: 1", Env{"OPTION_A": "1"}, false},
|
||||
|
||||
// parses export keyword
|
||||
{"export OPTION_A=2", Env{"OPTION_A": "2"}, false},
|
||||
|
||||
// expands newlines in quoted strings
|
||||
{`FOO="bar\nbaz"`, Env{"FOO": "bar\nbaz"}, false},
|
||||
|
||||
// parses varibales with "." in the name
|
||||
{`FOO.BAR=foobar`, Env{"FOO.BAR": "foobar"}, false},
|
||||
|
||||
// strips unquoted values
|
||||
{`foo=bar `, Env{"foo": "bar"}, false}, // not 'bar '
|
||||
|
||||
// ignores empty lines
|
||||
{"\n \t \nfoo=bar\n \nfizz=buzz", Env{"foo": "bar", "fizz": "buzz"}, false},
|
||||
|
||||
// ignores inline comments
|
||||
{"foo=bar # this is foo", Env{"foo": "bar"}, false},
|
||||
|
||||
// allows # in quoted value
|
||||
{`foo="bar#baz" # comment`, Env{"foo": "bar#baz"}, false},
|
||||
|
||||
// ignores comment lines
|
||||
{"\n\n\n # HERE GOES FOO \nfoo=bar", Env{"foo": "bar"}, false},
|
||||
|
||||
// parses # in quoted values
|
||||
{`foo="ba#r"`, Env{"foo": "ba#r"}, false},
|
||||
{"foo='ba#r'", Env{"foo": "ba#r"}, false},
|
||||
|
||||
// incorrect line format
|
||||
{"lol$wut", Env{}, false},
|
||||
}
|
||||
|
||||
var fixtures = []struct {
|
||||
filename string
|
||||
results Env
|
||||
}{
|
||||
{
|
||||
"fixtures/exported.env",
|
||||
Env{
|
||||
"OPTION_A": "2",
|
||||
"OPTION_B": `\n`,
|
||||
},
|
||||
},
|
||||
{
|
||||
"fixtures/plain.env",
|
||||
Env{
|
||||
"OPTION_A": "1",
|
||||
"OPTION_B": "2",
|
||||
"OPTION_C": "3",
|
||||
"OPTION_D": "4",
|
||||
"OPTION_E": "5",
|
||||
},
|
||||
},
|
||||
{
|
||||
"fixtures/quoted.env",
|
||||
Env{
|
||||
"OPTION_A": "1",
|
||||
"OPTION_B": "2",
|
||||
"OPTION_C": "",
|
||||
"OPTION_D": `\n`,
|
||||
"OPTION_E": "1",
|
||||
"OPTION_F": "2",
|
||||
"OPTION_G": "",
|
||||
"OPTION_H": "\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
"fixtures/yaml.env",
|
||||
Env{
|
||||
"OPTION_A": "1",
|
||||
"OPTION_B": "2",
|
||||
"OPTION_C": "",
|
||||
"OPTION_D": `\n`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
for i, tt := range formats {
|
||||
if tt.preset {
|
||||
os.Setenv("FOO", "test")
|
||||
}
|
||||
|
||||
exp := Parse(strings.NewReader(tt.in))
|
||||
|
||||
x := fmt.Sprintf("%+v\n", exp)
|
||||
o := fmt.Sprintf("%+v\n", tt.out)
|
||||
|
||||
if x != o {
|
||||
t.Logf("%q\n", tt.in)
|
||||
t.Errorf("(%d) %s != %s\n", i, x, o)
|
||||
}
|
||||
|
||||
os.Clearenv()
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
for i, tt := range fixtures {
|
||||
Load(tt.filename)
|
||||
|
||||
for key, val := range tt.results {
|
||||
if eval := os.Getenv(key); eval != val {
|
||||
t.Errorf("(%d) %s => %s != %s", i, key, eval, val)
|
||||
}
|
||||
}
|
||||
|
||||
os.Clearenv()
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadEnv(t *testing.T) {
|
||||
Load()
|
||||
|
||||
tkey := "HELLO"
|
||||
val := "world"
|
||||
|
||||
if tval := os.Getenv(tkey); tval != val {
|
||||
t.Errorf("%s => %s != %s", tkey, tval, val)
|
||||
}
|
||||
|
||||
os.Clearenv()
|
||||
}
|
||||
|
||||
func TestLoadNonExist(t *testing.T) {
|
||||
file := ".nonexist.env"
|
||||
|
||||
err := Load(file)
|
||||
if err == nil {
|
||||
t.Errorf("Load(`%s`) => error: `no such file or directory` != nil", file)
|
||||
}
|
||||
}
|
||||
@@ -21,4 +21,4 @@ test: lint build
|
||||
cd eg && ../forego start
|
||||
|
||||
$(BIN): $(SRC)
|
||||
godep go build -o $@
|
||||
go build -o $@
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/subosito/gotenv"
|
||||
"github.com/subosito/gotenv"
|
||||
)
|
||||
|
||||
var envEntryRegexp = regexp.MustCompile("^([A-Za-z_0-9]+)=(.*)$")
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/daviddengcn/go-colortext"
|
||||
"github.com/daviddengcn/go-colortext"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -40,7 +40,7 @@ func (of *OutletFactory) LineReader(wg *sync.WaitGroup, name string, index int,
|
||||
|
||||
for {
|
||||
buf := make([]byte, 1024)
|
||||
|
||||
|
||||
if n, err := reader.Read(buf); err != nil {
|
||||
return
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
_ "github.com/ddollar/forego/Godeps/_workspace/src/github.com/kr/pretty"
|
||||
_ "github.com/kr/pretty"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
|
||||
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/ddollar/dist"
|
||||
"github.com/ddollar/dist"
|
||||
)
|
||||
|
||||
var cmdUpdate = &Command{
|
||||
|
||||
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
+3
-3
@@ -2,7 +2,7 @@
|
||||
package dist
|
||||
|
||||
import (
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/bitbucket.org/kardianos/osext"
|
||||
"bitbucket.org/kardianos/osext"
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/ddollar/go-update"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/kr/binarydist"
|
||||
"github.com/ddollar/go-update"
|
||||
"github.com/kr/binarydist"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
Generated
Vendored
Generated
Vendored
+2
-2
@@ -29,7 +29,7 @@ download progress,
|
||||
package update
|
||||
|
||||
import (
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/bitbucket.org/kardianos/osext"
|
||||
"bitbucket.org/kardianos/osext"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -137,7 +137,7 @@ func NewDownload(url string) *Download {
|
||||
HttpClient: new(http.Client),
|
||||
Progress: make(chan int),
|
||||
Method: "GET",
|
||||
Url: url,
|
||||
Url: url,
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
+1
-1
@@ -2,7 +2,7 @@ package pretty
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/kr/text"
|
||||
"github.com/kr/text"
|
||||
"io"
|
||||
"reflect"
|
||||
"strconv"
|
||||
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Reference in New Issue
Block a user