mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Use runtime.GOOS to identify Windows specific path tests
This commit is contained in:
parent
0b5f8c8cb3
commit
e52a76f559
3 changed files with 32 additions and 54 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -398,6 +399,16 @@ func TestAbsPathify(t *testing.T) {
|
|||
{"dir", filepath.FromSlash("/work"), filepath.FromSlash("/work/dir")},
|
||||
}
|
||||
|
||||
windowsData := []test{
|
||||
{"c:\\banana\\..\\dir", "c:\\foo", "c:\\dir"},
|
||||
{"\\dir", "c:\\foo", "c:\\foo\\dir"},
|
||||
{"c:\\", "c:\\foo", "c:\\"},
|
||||
}
|
||||
|
||||
unixData := []test{
|
||||
{"/banana/../dir/", "/work", "/dir"},
|
||||
}
|
||||
|
||||
for i, d := range data {
|
||||
// todo see comment in AbsPathify
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
@ -407,6 +418,27 @@ func TestAbsPathify(t *testing.T) {
|
|||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
|
||||
}
|
||||
}
|
||||
t.Logf("Running platform specific path tests for %s", runtime.GOOS)
|
||||
if runtime.GOOS == "windows" {
|
||||
for i, d := range windowsData {
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
||||
expected := AbsPathify(d.inPath)
|
||||
if d.expected != expected {
|
||||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i, d := range unixData {
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
||||
expected := AbsPathify(d.inPath)
|
||||
if d.expected != expected {
|
||||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFilename(t *testing.T) {
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPlatformAbsPathify(t *testing.T) {
|
||||
type test struct {
|
||||
inPath, workingDir, expected string
|
||||
}
|
||||
data := []test{
|
||||
{"/banana/../dir/", "/work", "/dir"},
|
||||
}
|
||||
|
||||
for i, d := range data {
|
||||
// todo see comment in AbsPathify
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
||||
expected := AbsPathify(d.inPath)
|
||||
if d.expected != expected {
|
||||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPlatformAbsPathify(t *testing.T) {
|
||||
type test struct {
|
||||
inPath, workingDir, expected string
|
||||
}
|
||||
data := []test{
|
||||
{"c:\\banana\\..\\dir", "c:\\foo", "c:\\dir"},
|
||||
{"\\dir", "c:\\foo", "c:\\foo\\dir"},
|
||||
{"c:\\", "c:\\foo", "c:\\"},
|
||||
}
|
||||
|
||||
for i, d := range data {
|
||||
// todo see comment in AbsPathify
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
||||
expected := AbsPathify(d.inPath)
|
||||
if d.expected != expected {
|
||||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue