Skip to content

Commit

Permalink
Added test for cli.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mborho committed Mar 12, 2016
1 parent fccf330 commit aff9769
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cli.go
Expand Up @@ -23,7 +23,7 @@ import (
)

// Reads command line arguments and runs rem.
func run() error {
func run(remfile string) error {
// read flags
globalFlag := flag.Bool("g", false, "use global rem file")
helpFlag := flag.Bool("h", false, "show this help")
Expand All @@ -36,7 +36,7 @@ func run() error {
rem := &Rem{
global: *globalFlag,
File: File{
filename: ".rem",
filename: remfile,
},
}
rem.read()
Expand Down
23 changes: 23 additions & 0 deletions cli_test.go
@@ -0,0 +1,23 @@
package main

import (
"io/ioutil"
"os"
"testing"
)

func TestRunDefault(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

err := run(remfile)
if err != nil {
t.Error("Error when calling without argument!")
}

w.Close()
out, _ := ioutil.ReadAll(r)
os.Stdout = rescueStdout
t.Log(out)
}
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -17,7 +17,7 @@
package main

func main() {
if err := run(); err != nil {
if err := run(".rem"); err != nil {
exit(err)
}
}

0 comments on commit aff9769

Please sign in to comment.