mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-29 17:31:02 +02:00
Add AppVeyor Windows builds and releases (#206)
* Make some filenames Windows-friendly * Update references to renamed files * Fix escaped filenames to run on non-Windows platforms
This commit is contained in:
parent
d67779ed8d
commit
b0459e4867
57
main_test.go
57
main_test.go
@ -21,9 +21,14 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -217,21 +222,63 @@ func runTest(t *testing.T, test *mainTest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func expandEscapedFilenames(t *testing.T) error {
|
||||||
|
// Escaped filenames exist because their unescaped forms are invalid on
|
||||||
|
// Windows. We have no choice but to skip these in testing.
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
match, err := filepath.Glob("testdata/*%*")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
filenameEscapeRE := regexp.MustCompile(`%[0-9A-Fa-f]{2}`)
|
||||||
|
|
||||||
|
for _, input := range match {
|
||||||
|
file := filenameEscapeRE.ReplaceAllStringFunc(input, func(s string) string {
|
||||||
|
code, err := strconv.ParseUint(s[1:], 16, 8)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return string([]byte{byte(code)})
|
||||||
|
})
|
||||||
|
if file != input {
|
||||||
|
if err := os.Link(input, file); err != nil {
|
||||||
|
if !os.IsExist(err) {
|
||||||
|
return fmt.Errorf("linking %s -> %s: %v", file, input, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.Logf("Linked %s -> %s", input, file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(t *testing.T) {
|
func TestMain(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if err := expandEscapedFilenames(t); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
var mainTests []mainTest
|
var mainTests []mainTest
|
||||||
match, err := filepath.Glob("testdata/*.jsonnet")
|
match, err := filepath.Glob("testdata/*.jsonnet")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonnetExtRE := regexp.MustCompile(`\.jsonnet$`)
|
||||||
|
|
||||||
for _, input := range match {
|
for _, input := range match {
|
||||||
golden := input
|
// Skip escaped filenames.
|
||||||
name := input
|
if strings.ContainsRune(input, '%') {
|
||||||
if strings.HasSuffix(input, ".jsonnet") {
|
continue
|
||||||
name = input[:len(input)-len(".jsonnet")]
|
|
||||||
golden = name + ".golden"
|
|
||||||
}
|
}
|
||||||
|
name := jsonnetExtRE.ReplaceAllString(input, "")
|
||||||
|
golden := jsonnetExtRE.ReplaceAllString(input, ".golden")
|
||||||
var meta testMetadata
|
var meta testMetadata
|
||||||
if val, exists := metadataForTests[name]; exists {
|
if val, exists := metadataForTests[name]; exists {
|
||||||
meta = val
|
meta = val
|
||||||
|
0
testdata/".golden → testdata/%22.golden
vendored
0
testdata/".golden → testdata/%22.golden
vendored
0
testdata/'.golden → testdata/%27.golden
vendored
0
testdata/'.golden → testdata/%27.golden
vendored
4
testdata/.gitignore
vendored
Normal file
4
testdata/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
".golden
|
||||||
|
".jsonnet
|
||||||
|
'.golden
|
||||||
|
'.jsonnet
|
Loading…
x
Reference in New Issue
Block a user