add some useful func
Showing
4 changed files
with
29 additions
and
5 deletions
utils/caller.go
0 → 100644
utils/caller_test.go
0 → 100644
| ... | @@ -43,7 +43,7 @@ func LookFile(filename string, paths ...string) (fullpath string, err error) { | ... | @@ -43,7 +43,7 @@ func LookFile(filename string, paths ...string) (fullpath string, err error) { |
| 43 | // like command grep -E | 43 | // like command grep -E |
| 44 | // for example: GrepE(`^hello`, "hello.txt") | 44 | // for example: GrepE(`^hello`, "hello.txt") |
| 45 | // \n is striped while read | 45 | // \n is striped while read |
| 46 | func GrepE(patten string, filename string) (lines []string, err error) { | 46 | func GrepFile(patten string, filename string) (lines []string, err error) { |
| 47 | re, err := regexp.Compile(patten) | 47 | re, err := regexp.Compile(patten) |
| 48 | if err != nil { | 48 | if err != nil { |
| 49 | return | 49 | return | ... | ... |
| ... | @@ -22,7 +22,7 @@ func TestSelfDir(t *testing.T) { | ... | @@ -22,7 +22,7 @@ func TestSelfDir(t *testing.T) { |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | func TestFileExists(t *testing.T) { | 24 | func TestFileExists(t *testing.T) { |
| 25 | if !FileExists("/bin/echo") { | 25 | if !FileExists("./file.go") { |
| 26 | t.Errorf("/bin/echo should exists, but it didn't") | 26 | t.Errorf("/bin/echo should exists, but it didn't") |
| 27 | } | 27 | } |
| 28 | 28 | ||
| ... | @@ -44,14 +44,14 @@ func TestLookFile(t *testing.T) { | ... | @@ -44,14 +44,14 @@ func TestLookFile(t *testing.T) { |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | func TestGrepE(t *testing.T) { | 47 | func TestGrepFile(t *testing.T) { |
| 48 | _, err := GrepE("", noExistedFile) | 48 | _, err := GrepFile("", noExistedFile) |
| 49 | if err == nil { | 49 | if err == nil { |
| 50 | t.Error("expect file-not-existed error, but got nothing") | 50 | t.Error("expect file-not-existed error, but got nothing") |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | path := filepath.Join(".", "testdata", "grepe.test") | 53 | path := filepath.Join(".", "testdata", "grepe.test") |
| 54 | lines, err := GrepE(`^\s*[^#]+`, path) | 54 | lines, err := GrepFile(`^\s*[^#]+`, path) |
| 55 | if err != nil { | 55 | if err != nil { |
| 56 | t.Error(err) | 56 | t.Error(err) |
| 57 | } | 57 | } | ... | ... |
-
Please register or sign in to post a comment