mumukit 2.34.1 → 2.35.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecf5dad926913985cd2067a888f7e14233c66a70a887ee287d60093fd3d33faf
4
- data.tar.gz: 8e36f9461737a850f6c8a691b0e6524bbe58dbd7276e92b5c5e40f6ad4c407d4
3
+ metadata.gz: c93b40ab8d9ea10cfe1e73457763ef6146c396fbfe6feeab318e0e4938553fff
4
+ data.tar.gz: e7b34dad3b8a67f5be0468e720bfae08a985eae4f7b299886919a03a765367e3
5
5
  SHA512:
6
- metadata.gz: 6fbd065df141368fee19ddfbc7c9eb03df473ff1a0cf92cc2b4ab407dc35688ce7ac119cd778e63ad6a87a880f41fbe7c027645e652b959e13eb2355070618f6
7
- data.tar.gz: 7ea9f24a7635aec967c1c3ceb3df3458a533aacdd644596beb58bbb91fffa15ef62bbe785d9d5a984bafc80faa48bc75adb279da4765e2559381226227f829df
6
+ metadata.gz: 40a8ad3cbe13a399ae7d012819eff925497920cd1233e6b4f16db14aa5f60fe0b6b521c491532c77d36f7b1c5e998b3aa132275006fd55bab3b944c258f429ef
7
+ data.tar.gz: 5135710e6ebbb026321d6f36fdcb0139203612d75ec5255805158438ef7008cf469813ae778395c42aa1f16b3ccd8e47366a94f5ec8adcc75b624cff8ef75aa1
@@ -3,6 +3,7 @@ end
3
3
 
4
4
  require_relative './metatest/errors'
5
5
  require_relative './metatest/checker'
6
+ require_relative './metatest/test_result_builder'
6
7
  require_relative './metatest/interactive_checker'
7
8
  require_relative './metatest/framework'
8
- require_relative './metatest/identity_runner'
9
+ require_relative './metatest/identity_runner'
@@ -24,10 +24,12 @@ module Mumukit::Metatest
24
24
  ## }
25
25
  ##
26
26
  def check(input, example)
27
+ builder = Mumukit::Metatest::TestResultBuilder.new
28
+
27
29
  check_assertions input, postconditions_for(example), example
28
- [example[:name], :passed, render_success_output(input)]
30
+ build_passed_test_result builder, example, input
29
31
  rescue => e
30
- [example[:name], :failed, render_error_output(input, e.message)]
32
+ build_failed_test_result builder, example, input, e
31
33
  end
32
34
 
33
35
  ## If no postconditions are included in the example,
@@ -36,12 +38,34 @@ module Mumukit::Metatest
36
38
  example[:postconditions] || example.except(:name)
37
39
  end
38
40
 
39
- def render_success_output(value)
41
+ # Implementors may override this method instead of `build_success_output`
42
+ # if they don't want to handle error details.
43
+ #
44
+ # This method is only for backward compatibility. New code
45
+ # should use `build_success_output`.
46
+ def render_success_output(_input)
40
47
  nil
41
48
  end
42
49
 
43
- def render_error_output(value, error)
44
- error
50
+ # Implementors may override this method instead of `build_error_output`
51
+ # if they don't want to handle error details.
52
+ #
53
+ # This method is only for backward compatibility. New code
54
+ # should use `build_error_output`.
55
+ def render_error_output(_input, error_message)
56
+ error_message
57
+ end
58
+
59
+ # Implementors should override this method if they want access to
60
+ # the error details and produce more complex test results
61
+ def build_success_output(builder, _example, input)
62
+ builder.result = render_success_output input
63
+ end
64
+
65
+ # Implementors should override this method if they want access to
66
+ # the error details and produce more complex test results
67
+ def build_error_output(builder, input, _example, error)
68
+ builder.result = render_error_output input, error.message
45
69
  end
46
70
 
47
71
  def check_assertions(input, assertions_hash, example)
@@ -54,16 +78,30 @@ module Mumukit::Metatest
54
78
  send "check_#{assertion_name}", input, assertion_config
55
79
  end
56
80
 
57
- def fail(message)
58
- raise Mumukit::Metatest::Failed, message
81
+ def fail(message, details: nil)
82
+ raise Mumukit::Metatest::Failed.new(message, details)
83
+ end
84
+
85
+ def abort(message, details: nil)
86
+ raise Mumukit::Metatest::Aborted.new(message, details)
87
+ end
88
+
89
+ def error(message, details: nil)
90
+ raise Mumukit::Metatest::Errored.new(message, details)
59
91
  end
60
92
 
61
- def abort(message)
62
- raise Mumukit::Metatest::Aborted, message
93
+ def build_passed_test_result(builder, example, input)
94
+ builder.title = example[:name]
95
+ builder.status = :passed
96
+ build_success_output builder, example, input
97
+ builder.build
63
98
  end
64
99
 
65
- def error(message)
66
- raise Mumukit::Metatest::Errored, message
100
+ def build_failed_test_result(builder, example, input, e)
101
+ builder.title = example[:name]
102
+ builder.status = :failed
103
+ build_error_output builder, example, input, e
104
+ builder.build
67
105
  end
68
106
  end
69
107
  end
@@ -1,10 +1,17 @@
1
1
  module Mumukit::Metatest
2
- class Aborted < StandardError
2
+ class BaseError < StandardError
3
+ attr_reader :details
4
+ def initialize(message = "", details = nil)
5
+ super(message)
6
+ @details = details
7
+ end
8
+ end
9
+ class Aborted < BaseError
3
10
  end
4
11
 
5
- class Errored < StandardError
12
+ class Errored < BaseError
6
13
  end
7
14
 
8
- class Failed < StandardError
15
+ class Failed < BaseError
9
16
  end
10
- end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Mumukit::Metatest
2
+ class TestResultBuilder
3
+ attr_accessor :title, :status, :result, :summary_type, :summary_message
4
+
5
+ def summary
6
+ {type: summary_type.presence, message: summary_message.presence}.compact
7
+ end
8
+
9
+ def build
10
+ raise 'missing status' unless status
11
+ raise "invalid #{status}" unless status.passed? || status.failed?
12
+
13
+ if summary_message.present? || summary_type.present?
14
+ [title, status, result, summary]
15
+ else
16
+ [title, status, result]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -58,10 +58,16 @@ class Mumukit::Server::ResponseBuilder
58
58
  end
59
59
 
60
60
  def structured_base_response(test_results)
61
- {testResults: test_results[0].map { |title, status, result|
62
- {title: title,
63
- status: status,
64
- result: result} }}
61
+ {
62
+ testResults: test_results[0].map do |title, status, result, summary|
63
+ { summary: summary&.compact.presence }
64
+ .compact
65
+ .merge(
66
+ title: title,
67
+ status: status,
68
+ result: result)
69
+ end
70
+ }
65
71
  end
66
72
 
67
73
  def unstructured_base_response(test_results)
@@ -1,3 +1,3 @@
1
1
  module Mumukit
2
- VERSION = '2.34.1'
2
+ VERSION = '2.35.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumukit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.34.1
4
+ version: 2.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-08 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -323,6 +323,7 @@ files:
323
323
  - lib/mumukit/metatest/framework.rb
324
324
  - lib/mumukit/metatest/identity_runner.rb
325
325
  - lib/mumukit/metatest/interactive_checker.rb
326
+ - lib/mumukit/metatest/test_result_builder.rb
326
327
  - lib/mumukit/request_validation_error.rb
327
328
  - lib/mumukit/runner.rb
328
329
  - lib/mumukit/runtime.rb