Skip to content

Commit 6bd7a1b

Browse files
committed
- Improve JSON schema tests
1 parent 9c5eb67 commit 6bd7a1b

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

bashly}.json

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This folder contains invalid schema validations.
2+
3+
Each subfolder is named after the schema.
4+
5+
The tests can be run with `run schema invalid` and are included in the
6+
`run schema all` test (which is executed in CI).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo: bar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo: bar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo: bar

support/runfile/schema.runfile

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ action :all do
66
check_settings
77
check_strings
88
check_arbitrary
9+
check_invalid
910
end
1011

1112
help 'Test the bashly schema against a single example'
@@ -24,6 +25,9 @@ action(:strings) { check_strings }
2425
help 'Test the bashly schema against a bashly configuration that includes arbitrary (x-) keys'
2526
action(:arbitrary) { check_arbitrary }
2627

28+
help 'Verify that all the invalid schemas in spec/fixtures/schemas_invalid fail as expected'
29+
action(:invalid) { check_invalid }
30+
2731
helpers do
2832
def check_examples
2933
say "\ngub`Examples`"
@@ -34,21 +38,38 @@ helpers do
3438
end
3539

3640
def check_settings
37-
say "\ngub`Settings`"
41+
say "\ngub`Settings schema`"
3842
file = 'lib/bashly/libraries/settings/settings.yml'
3943
schema_check file, :settings
44+
say "\ngub`Settings schema PASS`"
4045
end
4146

4247
def check_strings
43-
say "\ngub`Strings`"
48+
say "\ngub`Strings schema`"
4449
file = 'lib/bashly/libraries/strings/strings.yml'
4550
schema_check file, :strings
51+
say "\ngub`Strings schema PASS`"
4652
end
4753

4854
def check_arbitrary
49-
say "\ngub`Arbitrary`"
55+
say "\ngub`Arbitrary arguments`"
5056
file = 'spec/fixtures/script/x_arbitrary.yml'
5157
schema_check file
58+
say "\ngub`Arbitrary arguments PASS`"
59+
end
60+
61+
def check_invalid
62+
say "\ngub`Invalid files`"
63+
basedir = 'spec/fixtures/schemas_invalid'
64+
files = Dir.chdir(basedir) { Dir['**/*.yml'] }
65+
66+
files.each do |file|
67+
schema = File.dirname file
68+
path = "#{basedir}/#{file}"
69+
schema_anticheck path, schema
70+
end
71+
72+
say "\ngub`Invalid files PASS`"
5273
end
5374

5475
def schema_check(file, schema = 'bashly')
@@ -58,4 +79,12 @@ helpers do
5879

5980
abort 'Failed' unless success
6081
end
82+
83+
def schema_anticheck(file, schema = 'bashly')
84+
command = "check-jsonschema --schemafile schemas/#{schema}.json #{file}"
85+
say "\nnb`$ check-jsonschema` [m`#{schema}`] bb`#{file}`"
86+
success = system "#{command}"
87+
88+
abort 'Failed' if success
89+
end
6190
end

0 commit comments

Comments
 (0)