@@ -6,6 +6,24 @@ action :all do
66 check_settings
77 check_strings
88 check_arbitrary
9+ check_invalid
10+ end
11+
12+ help 'Test any file against any schema'
13+ usage 'file [--anti] PATH [SCHEMA]'
14+ option '-a, --anti', 'Run anticheck instead (expect failure)'
15+ param 'PATH', 'The path to the tested YAML file'
16+ param 'SCHEMA', 'The name of the schema (bashly, settings of strings) [default: bashly]'
17+ example 'run schema file -a spec/fixtures/schemas_invalid/bashly/1.yml'
18+ example 'run schema file -a spec/fixtures/schemas_invalid/settings/2.yml settings'
19+ action(:file) do |args|
20+ schema = args['SCHEMA'] || 'bashly'
21+ if args['--anti']
22+ schema_anticheck args['PATH'], schema
23+ else
24+ schema_check args['PATH'], schema
25+ end
26+ say "\ngub`PASS`"
927end
1028
1129help 'Test the bashly schema against a single example'
@@ -24,31 +42,52 @@ action(:strings) { check_strings }
2442help 'Test the bashly schema against a bashly configuration that includes arbitrary (x-) keys'
2543action(:arbitrary) { check_arbitrary }
2644
45+ help 'Verify that all the invalid schemas in spec/fixtures/schemas_invalid fail as expected'
46+ action(:invalid) { check_invalid }
47+
2748helpers do
2849 def check_examples
2950 say "\ngub`Examples`"
3051 Example.all.each do |example|
3152 file = example.yaml_path
3253 schema_check file
3354 end
55+ say "\ngub`Examples PASS`"
3456 end
3557
3658 def check_settings
37- say "\ngub`Settings`"
59+ say "\ngub`Settings schema `"
3860 file = 'lib/bashly/libraries/settings/settings.yml'
3961 schema_check file, :settings
62+ say "\ngub`Settings schema PASS`"
4063 end
4164
4265 def check_strings
43- say "\ngub`Strings`"
66+ say "\ngub`Strings schema `"
4467 file = 'lib/bashly/libraries/strings/strings.yml'
4568 schema_check file, :strings
69+ say "\ngub`Strings schema PASS`"
4670 end
4771
4872 def check_arbitrary
49- say "\ngub`Arbitrary`"
73+ say "\ngub`Arbitrary arguments `"
5074 file = 'spec/fixtures/script/x_arbitrary.yml'
5175 schema_check file
76+ say "\ngub`Arbitrary arguments PASS`"
77+ end
78+
79+ def check_invalid
80+ say "\ngub`Invalid files`"
81+ basedir = 'spec/fixtures/schemas_invalid'
82+ files = Dir.chdir(basedir) { Dir['**/*.yml'] }
83+
84+ files.each do |file|
85+ schema = File.dirname file
86+ path = "#{basedir}/#{file}"
87+ schema_anticheck path, schema
88+ end
89+
90+ say "\ngub`Invalid files PASS`"
5291 end
5392
5493 def schema_check(file, schema = 'bashly')
@@ -58,4 +97,12 @@ helpers do
5897
5998 abort 'Failed' unless success
6099 end
100+
101+ def schema_anticheck(file, schema = 'bashly')
102+ command = "check-jsonschema --schemafile schemas/#{schema}.json #{file}"
103+ say "\nnb`$ check-jsonschema` [m`#{schema}`] bb`#{file}`"
104+ success = system "#{command}"
105+
106+ abort 'Failed' if success
107+ end
61108end
0 commit comments