Skip to content

Commit

Permalink
fix tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
judwhite committed Apr 23, 2017
1 parent 0a74732 commit 30b0f84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion generator_test.go
Expand Up @@ -44,11 +44,16 @@ func TestGenAbsPath(t *testing.T) {
parts := strings.Split(dir, string(filepath.Separator))
parent := strings.Join(parts[:len(parts)-1], string(filepath.Separator))

root := os.Args[0]
for root != filepath.Dir(root) {
root = filepath.Dir(root)
}

cases := []struct {
in string
out string
}{
{in: "/", out: "/"},
{in: "/", out: root},
{in: ".", out: dir},
{in: "../", out: parent},
}
Expand Down
9 changes: 8 additions & 1 deletion parser_test.go
Expand Up @@ -6,11 +6,12 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"
)

const rootDir = "/tmp/gohero"
var rootDir string

const indexHTML = `
<!DOCTYPE html>
Expand Down Expand Up @@ -78,6 +79,12 @@ const listToWriterWithResultHTML = `
`

func init() {
if runtime.GOOS != "windows" {
rootDir = "/tmp/gohero"
} else {
rootDir = `C:\tmp\gohero`
}

_, err := os.Stat(rootDir)
if !os.IsNotExist(err) {
if err = os.RemoveAll(rootDir); err != nil {
Expand Down
9 changes: 7 additions & 2 deletions util_test.go
Expand Up @@ -2,13 +2,18 @@ package hero

import (
"bytes"
"runtime"
"testing"
)

func TestExecCommand(t *testing.T) {
// test for panic
execCommand("")
execCommand("ls")
if runtime.GOOS != "windows" {
execCommand("")
execCommand("ls")
} else {
execCommand("dir")
}
}

func TestFormatUint(t *testing.T) {
Expand Down

0 comments on commit 30b0f84

Please sign in to comment.