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:
Marcelo Cantos 2018-03-13 11:46:57 +11:00 committed by Dave Cunningham
parent d67779ed8d
commit b0459e4867
6 changed files with 56 additions and 5 deletions

View File

@ -21,9 +21,14 @@ import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"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) {
flag.Parse()
if err := expandEscapedFilenames(t); err != nil {
t.Fatal(err)
}
var mainTests []mainTest
match, err := filepath.Glob("testdata/*.jsonnet")
if err != nil {
t.Fatal(err)
}
jsonnetExtRE := regexp.MustCompile(`\.jsonnet$`)
for _, input := range match {
golden := input
name := input
if strings.HasSuffix(input, ".jsonnet") {
name = input[:len(input)-len(".jsonnet")]
golden = name + ".golden"
// Skip escaped filenames.
if strings.ContainsRune(input, '%') {
continue
}
name := jsonnetExtRE.ReplaceAllString(input, "")
golden := jsonnetExtRE.ReplaceAllString(input, ".golden")
var meta testMetadata
if val, exists := metadataForTests[name]; exists {
meta = val

4
testdata/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
".golden
".jsonnet
'.golden
'.jsonnet