Module: Bparity::SpecBundle::Validator

Defined in:
lib/bparity/spec_bundle.rb

Constant Summary collapse

PROVENANCE_LEVELS =
%w[A B C D].freeze
FORMAL_LEVELS =
%w[F0 F1 F2 F3 F4].freeze
CONFORMANCE_MODES =
%w[strict refinement contract].freeze

Class Method Summary collapse

Class Method Details

.validate!(bundle, verify_checksum: true) ⇒ Object

Raises:



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