diff --git a/main.go b/main.go index c1b4120cbe58e49438f8ed0e4a8cb2a48c683bfd..a21d14ad0f27a509f21d8ffa43f1e02b7a9c6a26 100644 --- a/main.go +++ b/main.go @@ -70,6 +70,7 @@ func realMain(args []string) int { if !filepath.IsAbs(pattern) { pattern = filepath.Join(dir, pattern) } + docs = append(docs, glob(pattern)...) } if err := scanner.Err(); err != nil { @@ -90,7 +91,7 @@ func realMain(args []string) int { for _, p := range glob(ref) { absPath, absPathErr := filepath.Abs(p) 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 { @@ -124,6 +125,7 @@ func realMain(args []string) int { failures := make([]string, 0) errors := make([]string, 0) for _, p := range docs { + //fmt.Println(p) wg.Add(1) go func(path string) { defer wg.Done() @@ -233,14 +235,18 @@ func glob(pattern string) []string { if err != nil { log.Fatal(err) } + universalPaths := make([]string, 0) paths, err := filepath.Glob(pattern) + for _, mypath := range paths { + universalPaths = append(universalPaths, filepath.ToSlash(mypath)) + } if err != nil { log.Fatal(err) } - if len(paths) == 0 { + if len(universalPaths) == 0 { log.Fatalf("%s: no such file or directory", pattern) } - return paths + return universalPaths } type stringFlags []string diff --git a/main_test.go b/main_test.go index dcefe3ab5773cb4da6acf9efb9fb43814df2dc3e..875ba19dc7967d15ff940e810beb2476a8f25733 100644 --- a/main_test.go +++ b/main_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build windows !windows package main @@ -6,7 +6,25 @@ import ( "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"}) if exit != 0 { log.Fatalf("exit: got %d, want 0", exit) @@ -15,7 +33,34 @@ func ExampleMain_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"}) if exit != 1 { log.Fatalf("exit: got %d, want 1", exit) @@ -24,21 +69,50 @@ func ExampleMain_fail() { // 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"}) if exit != 2 { log.Fatalf("exit: got %d, want 2", exit) } // 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"}) if exit != 3 { log.Fatalf("exit: got %d, want 3", exit) } // 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 } + +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 +} diff --git a/main_windows_test.go b/main_windows_test.go deleted file mode 100644 index 567ab6f9fcc7721ffb4a8156ce3cb374ae4bad54..0000000000000000000000000000000000000000 --- a/main_windows_test.go +++ /dev/null @@ -1,118 +0,0 @@ -// +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 -}