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" "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

4
testdata/.gitignore vendored Normal file
View File

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