Skip to content

Commit b0459e4

Browse files
marcelocantossparkprime
authored andcommitted
Add AppVeyor Windows builds and releases (google#206)
* Make some filenames Windows-friendly * Update references to renamed files * Fix escaped filenames to run on non-Windows platforms
1 parent d67779e commit b0459e4

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

main_test.go

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"flag"
24+
"fmt"
2425
"io/ioutil"
26+
"os"
2527
"os/exec"
2628
"path/filepath"
29+
"regexp"
30+
"runtime"
31+
"strconv"
2732
"strings"
2833
"testing"
2934

@@ -217,21 +222,63 @@ func runTest(t *testing.T, test *mainTest) {
217222
}
218223
}
219224

225+
func expandEscapedFilenames(t *testing.T) error {
226+
// Escaped filenames exist because their unescaped forms are invalid on
227+
// Windows. We have no choice but to skip these in testing.
228+
if runtime.GOOS == "windows" {
229+
return nil
230+
}
231+
232+
match, err := filepath.Glob("testdata/*%*")
233+
if err != nil {
234+
return err
235+
}
236+
237+
filenameEscapeRE := regexp.MustCompile(`%[0-9A-Fa-f]{2}`)
238+
239+
for _, input := range match {
240+
file := filenameEscapeRE.ReplaceAllStringFunc(input, func(s string) string {
241+
code, err := strconv.ParseUint(s[1:], 16, 8)
242+
if err != nil {
243+
panic(err)
244+
}
245+
return string([]byte{byte(code)})
246+
})
247+
if file != input {
248+
if err := os.Link(input, file); err != nil {
249+
if !os.IsExist(err) {
250+
return fmt.Errorf("linking %s -> %s: %v", file, input, err)
251+
}
252+
}
253+
t.Logf("Linked %s -> %s", input, file)
254+
}
255+
}
256+
257+
return nil
258+
}
259+
220260
func TestMain(t *testing.T) {
221261
flag.Parse()
262+
263+
if err := expandEscapedFilenames(t); err != nil {
264+
t.Fatal(err)
265+
}
266+
222267
var mainTests []mainTest
223268
match, err := filepath.Glob("testdata/*.jsonnet")
224269
if err != nil {
225270
t.Fatal(err)
226271
}
227272

273+
jsonnetExtRE := regexp.MustCompile(`\.jsonnet$`)
274+
228275
for _, input := range match {
229-
golden := input
230-
name := input
231-
if strings.HasSuffix(input, ".jsonnet") {
232-
name = input[:len(input)-len(".jsonnet")]
233-
golden = name + ".golden"
276+
// Skip escaped filenames.
277+
if strings.ContainsRune(input, '%') {
278+
continue
234279
}
280+
name := jsonnetExtRE.ReplaceAllString(input, "")
281+
golden := jsonnetExtRE.ReplaceAllString(input, ".golden")
235282
var meta testMetadata
236283
if val, exists := metadataForTests[name]; exists {
237284
meta = val
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

testdata/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
".golden
2+
".jsonnet
3+
'.golden
4+
'.jsonnet

0 commit comments

Comments
 (0)