37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/bparity/spec_bundle.rb', line 37
def validate!(bundle, verify_checksum: true)
unless bundle.is_a?(Hash) && bundle["spec_bundle_version"] == VERSION
raise InvalidBundleError, "Spec Bundle version 2 is required. Run `bparity synthesize` again."
end
unless bundle["subjects"].is_a?(Array) && !bundle["subjects"].empty?
raise InvalidBundleError,
"The Spec Bundle has no subjects. Record a corpus and run `bparity synthesize`."
end
mode = bundle.fetch("conformance_mode", "refinement")
invalid!("conformance_mode must be strict, refinement, or contract") unless CONFORMANCE_MODES.include?(mode)
invalid!("canonicalization must be an object") unless bundle.fetch("canonicalization", {}).is_a?(Hash)
validate_subjects!(bundle.fetch("subjects"))
validate_lts!(bundle)
return bundle unless verify_checksum
unless bundle["checksum"]
raise InvalidBundleError,
"The Spec Bundle has no checksum. Run `bparity synthesize` again."
end
return bundle if bundle["checksum"] == Checksum.calculate(bundle)
raise InvalidBundleError,
"The Spec Bundle checksum does not match. Do not edit it by hand; run `bparity synthesize` again."
end
|