Skip to content
Snippets Groups Projects
Commit 717589cb authored by Ken Brooks's avatar Ken Brooks
Browse files

attempting to make a universal test

parent 896f3e4c
No related branches found
No related tags found
No related merge requests found
...@@ -70,6 +70,7 @@ func realMain(args []string) int { ...@@ -70,6 +70,7 @@ func realMain(args []string) int {
if !filepath.IsAbs(pattern) { if !filepath.IsAbs(pattern) {
pattern = filepath.Join(dir, pattern) pattern = filepath.Join(dir, pattern)
} }
docs = append(docs, glob(pattern)...) docs = append(docs, glob(pattern)...)
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
...@@ -90,7 +91,7 @@ func realMain(args []string) int { ...@@ -90,7 +91,7 @@ func realMain(args []string) int {
for _, p := range glob(ref) { for _, p := range glob(ref) {
absPath, absPathErr := filepath.Abs(p) absPath, absPathErr := filepath.Abs(p)
if absPathErr != nil { if absPathErr != nil {
log.Fatalf("%s: unable to convert to absolute path: %s\n", absPath, err) log.Fatalf("%s: unable to convert to absolute path: %s\n", absPath, absPathErr)
} }
if absPath == schemaPath { if absPath == schemaPath {
...@@ -124,6 +125,7 @@ func realMain(args []string) int { ...@@ -124,6 +125,7 @@ func realMain(args []string) int {
failures := make([]string, 0) failures := make([]string, 0)
errors := make([]string, 0) errors := make([]string, 0)
for _, p := range docs { for _, p := range docs {
//fmt.Println(p)
wg.Add(1) wg.Add(1)
go func(path string) { go func(path string) {
defer wg.Done() defer wg.Done()
...@@ -233,14 +235,18 @@ func glob(pattern string) []string { ...@@ -233,14 +235,18 @@ func glob(pattern string) []string {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
universalPaths := make([]string, 0)
paths, err := filepath.Glob(pattern) paths, err := filepath.Glob(pattern)
for _, mypath := range paths {
universalPaths = append(universalPaths, filepath.ToSlash(mypath))
}
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
if len(paths) == 0 { if len(universalPaths) == 0 {
log.Fatalf("%s: no such file or directory", pattern) log.Fatalf("%s: no such file or directory", pattern)
} }
return paths return universalPaths
} }
type stringFlags []string type stringFlags []string
......
// +build !windows // +build windows !windows
package main package main
...@@ -6,7 +6,25 @@ import ( ...@@ -6,7 +6,25 @@ import (
"log" "log"
) )
func ExampleMain_pass() { func ExampleMain_pass_ymlschema_ymldoc() {
exit := realMain([]string{"-s", "testdata/schema.yml", "testdata/data-pass.yml"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata/data-pass.yml: pass
}
func ExampleMain_pass_jsonschema_ymldoc() {
exit := realMain([]string{"-s", "testdata/schema.json", "testdata/data-pass.yml"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata/data-pass.yml: pass
}
func ExampleMain_pass_jsonschema_jsondoc() {
exit := realMain([]string{"-s", "testdata/schema.json", "testdata/data-pass.json"}) exit := realMain([]string{"-s", "testdata/schema.json", "testdata/data-pass.json"})
if exit != 0 { if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit) log.Fatalf("exit: got %d, want 0", exit)
...@@ -15,7 +33,34 @@ func ExampleMain_pass() { ...@@ -15,7 +33,34 @@ func ExampleMain_pass() {
// testdata/data-pass.json: pass // testdata/data-pass.json: pass
} }
func ExampleMain_fail() { func ExampleMain_pass_ymlschema_jsondoc() {
exit := realMain([]string{"-s", "testdata/schema.yml", "testdata/data-pass.json"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata/data-pass.json: pass
}
func ExampleMain_fail_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.yml", "testdata/data-fail.yml"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata/data-fail.yml: fail: (root): foo is required
}
func ExampleMain_fail_jsonschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.json", "testdata/data-fail.yml"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata/data-fail.yml: fail: (root): foo is required
}
func ExampleMain_fail_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.json", "testdata/data-fail.json"}) exit := realMain([]string{"-q", "-s", "testdata/schema.json", "testdata/data-fail.json"})
if exit != 1 { if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit) log.Fatalf("exit: got %d, want 1", exit)
...@@ -24,21 +69,50 @@ func ExampleMain_fail() { ...@@ -24,21 +69,50 @@ func ExampleMain_fail() {
// testdata/data-fail.json: fail: (root): foo is required // testdata/data-fail.json: fail: (root): foo is required
} }
func ExampleMain_error() { func ExampleMain_fail_ymlschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.yml", "testdata/data-fail.json"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata/data-fail.json: fail: (root): foo is required
}
func ExampleMain_error_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.json", "testdata/data-error.json"}) exit := realMain([]string{"-q", "-s", "testdata/schema.json", "testdata/data-error.json"})
if exit != 2 { if exit != 2 {
log.Fatalf("exit: got %d, want 2", exit) log.Fatalf("exit: got %d, want 2", exit)
} }
// Output: // Output:
// testdata/data-error.json: error: invalid character 'o' in literal null (expecting 'u') // testdata/data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')
} }
func ExampleMain_glob() { func ExampleMain_error_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.yml", "testdata/data-error.yml"})
if exit != 2 {
log.Fatalf("exit: got %d, want 2", exit)
}
// Output:
// testdata/data-error.yml: error: load doc yaml: found unexpected end of stream
}
func ExampleMain_glob_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.json", "testdata/data-*.json"}) exit := realMain([]string{"-q", "-s", "testdata/schema.json", "testdata/data-*.json"})
if exit != 3 { if exit != 3 {
log.Fatalf("exit: got %d, want 3", exit) log.Fatalf("exit: got %d, want 3", exit)
} }
// Unordered output: // Unordered output:
// testdata/data-error.json: error: invalid character 'o' in literal null (expecting 'u') // testdata/data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')
// testdata/data-fail.json: fail: (root): foo is required // testdata/data-fail.json: fail: (root): foo is required
} }
func ExampleMain_glob_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata/schema.yml", "testdata/data-*.yml"})
if exit != 3 {
log.Fatalf("exit: got %d, want 3", exit)
}
// Unordered output:
// testdata/data-fail.yml: fail: (root): foo is required
//
// testdata/data-error.yml: error: load doc yaml: found unexpected end of stream
}
// +build windows
package main
import (
"log"
)
func ExampleMain_pass_ymlschema_ymldoc() {
exit := realMain([]string{"-s", "testdata\\schema.yml", "testdata\\data-pass.yml"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata\data-pass.yml: pass
}
func ExampleMain_pass_jsonschema_ymldoc() {
exit := realMain([]string{"-s", "testdata\\schema.json", "testdata\\data-pass.yml"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata\data-pass.yml: pass
}
func ExampleMain_pass_jsonschema_jsondoc() {
exit := realMain([]string{"-s", "testdata\\schema.json", "testdata\\data-pass.json"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata\data-pass.json: pass
}
func ExampleMain_pass_ymlschema_jsondoc() {
exit := realMain([]string{"-s", "testdata\\schema.yml", "testdata\\data-pass.json"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata\data-pass.json: pass
}
func ExampleMain_fail_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-fail.yml"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata\data-fail.yml: fail: (root): foo is required
}
func ExampleMain_fail_jsonschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-fail.yml"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata\data-fail.yml: fail: (root): foo is required
}
func ExampleMain_fail_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-fail.json"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata\data-fail.json: fail: (root): foo is required
}
func ExampleMain_fail_ymlschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-fail.json"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata\data-fail.json: fail: (root): foo is required
}
func ExampleMain_error_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-error.json"})
if exit != 2 {
log.Fatalf("exit: got %d, want 2", exit)
}
// Output:
// testdata\data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')
}
func ExampleMain_error_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-error.yml"})
if exit != 2 {
log.Fatalf("exit: got %d, want 2", exit)
}
// Output:
// testdata\data-error.yml: error: load doc yaml: found unexpected end of stream
}
func ExampleMain_glob_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-*.json"})
if exit != 3 {
log.Fatalf("exit: got %d, want 3", exit)
}
// Unordered output:
// testdata\data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')
// testdata\data-fail.json: fail: (root): foo is required
}
func ExampleMain_glob_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-*.yml"})
if exit != 3 {
log.Fatalf("exit: got %d, want 3", exit)
}
// Unordered output:
// testdata\data-error.yml: error: load doc yaml: found unexpected end of stream
//
// testdata\data-fail.yml: fail: (root): foo is required
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment