mumukit 2.9.0 → 2.10.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
  SHA1:
3
- metadata.gz: 21c46d72fc20503bd751e4ef3b798b006d6d2857
4
- data.tar.gz: 7ea814106ca4d802e729eb2a0131c11051be45b9
3
+ metadata.gz: 35638ca8f8f4793021d2e0cf43b60e62d8cbc5b7
4
+ data.tar.gz: 6fea9eb121d02c2db837ef23efae0649fc9e204a
5
5
  SHA512:
6
- metadata.gz: cb397d1d351c9958717d5e604a1a9cf5099ad40ca55ce574cb668fde10ba4b788639a35648bbeb7a5a66ebfc39b6a7b511113780d8fc0982d5a66a31fb72a165
7
- data.tar.gz: 86d56d7eb5d463deae54fe44268856dd149fc86437fd7464a6e79e14862beddc56309c55e3ef2dc3dca30102fc9b73da2a3696083da925a01b47a58402d70397
6
+ metadata.gz: 03b79127fdc4df1954b04cd83bbf559934662e85d6b8d36687c053606af96b3a1d35dbd1c6a4046fbfb0fb100533e2602bd703aeaf2f2ac8ca7379a92b9d752a
7
+ data.tar.gz: 9f0f259eba97f1efc7e8339774cbbeff9889c279ed26b37733dbd940980c070f0b8fd5909814f62849d472cf71d6ba3807800ba2a97ed97e790534bb1d608b70
@@ -69,7 +69,7 @@ class Mumukit::Server::TestServer
69
69
 
70
70
  def run_expectations!(request)
71
71
  if request.expectations
72
- compile_and_run runtime.expectations_hook, request
72
+ compile_and_run(runtime.expectations_hook, request) { [] }
73
73
  else
74
74
  []
75
75
  end
@@ -85,7 +85,7 @@ class Mumukit::Server::TestServer
85
85
  compilation = hook.compile(preprocess request)
86
86
  hook.run!(compilation)
87
87
  rescue Mumukit::CompilationError => e
88
- [e.message, :errored]
88
+ block_given? ? yield(e) : [e.message, :errored]
89
89
  end
90
90
 
91
91
  def preprocess(request)
@@ -1,7 +1,15 @@
1
+ require 'mumukit/inspection'
2
+
1
3
  module Mumukit
2
4
  class Templates::MulangExpectationsHook < Mumukit::Templates::FileHook
3
- isolated false
5
+ LOGIC_SMELLS = %w(UsesCut UsesFail UsesUnificationOperator HasRedundantReduction)
6
+ FUNCTIONAL_SMELLS = %w(HasRedundantParameter HasRedundantGuards)
7
+ OBJECT_ORIENTED_SMELLS = %w(DoesNullTest ReturnsNull)
8
+ IMPERATIVE_SMELLS = %w(HasRedundantLocalVariableReturn HasAssignmentReturn)
9
+ EXPRESSIVENESS_SMELLS = %w(HasTooShortBindings HasWrongCaseBindings HasMisspelledBindings)
10
+ GENERIC_SMELLS = %w(IsLongCode HasCodeDuplication HasRedundantLambda HasRedundantIf DoesTypeTest HasRedundantBooleanComparison)
4
11
 
12
+ isolated false
5
13
  required :language, 'You have to provide a Mulang-compatible language in order to use this hook'
6
14
 
7
15
  def tempfile_extension
@@ -9,11 +17,14 @@ module Mumukit
9
17
  end
10
18
 
11
19
  def command_line(filename)
12
- "cat #{filename} | #{mulang_path} -s"
20
+ # TODO avoid file generation
21
+ "cat #{filename} | #{mulang_path} -s 2>&1"
13
22
  end
14
23
 
15
24
  def post_process_file(file, result, status)
16
25
  parse_response JSON.pretty_parse(result)
26
+ rescue JSON::ParserError
27
+ raise Mumukit::CompilationError, "Can not handle mulang results #{result}"
17
28
  end
18
29
 
19
30
  def compile_file_content(request)
@@ -21,24 +32,70 @@ module Mumukit
21
32
  end
22
33
 
23
34
  def compile_json_file_content(request)
35
+ expectations, exceptions = compile_expectations_and_exceptions request
24
36
  {
25
- expectations: request[:expectations].map { |it| compile_expectation(it.deep_symbolize_keys) },
26
- code: {
27
- content: compile_content(request[:content]),
28
- language: language}
37
+ sample: compile_sample(request),
38
+ spec: {
39
+ expectations: expectations,
40
+ smellsSet: {
41
+ tag: 'AllSmells',
42
+ exclude: (exceptions + default_smell_exceptions)
43
+ }
44
+ }
29
45
  }
30
46
  end
31
47
 
48
+ def default_smell_exceptions
49
+ []
50
+ end
51
+
52
+ def compile_sample(request)
53
+ compiled_content = compile_content(request[:content])
54
+ if language == 'Mulang'
55
+ {
56
+ tag: 'MulangSample',
57
+ ast: compiled_content
58
+ }
59
+ else
60
+ {
61
+ tag: 'CodeSample',
62
+ language: language,
63
+ content: compiled_content
64
+ }
65
+ end
66
+ end
67
+
68
+ def compile_expectations_and_exceptions(request)
69
+ expectations = []
70
+ exceptions = []
71
+ request[:expectations].each do |it|
72
+ fill_expectations_and_excetions it.deep_symbolize_keys, expectations, exceptions
73
+ end
74
+ [expectations, exceptions]
75
+ end
76
+
77
+ def fill_expectations_and_excetions(expectation, expectations, exceptions)
78
+ inspection = expectation[:inspection]
79
+ if inspection&.start_with? 'Except:'
80
+ exceptions << inspection[7..-1]
81
+ else
82
+ expectations << compile_expectation(expectation)
83
+ end
84
+ end
85
+
32
86
  def compile_content(content)
33
87
  content
34
88
  end
35
89
 
36
90
  def compile_expectation(expectation)
37
- (expectation[:verb].present? ? {tag: :Advanced} : {tag: :Basic}).merge(expectation)
91
+ Mumukit::Inspection::Expectation.parse(expectation).as_v2.to_h
38
92
  end
39
93
 
40
94
  def parse_response(response)
41
- response['results'].map do |it|
95
+ if response['tag'] == 'AnalysisFailed'
96
+ raise Mumukit::CompilationError, response['reason']
97
+ end
98
+ response['expectationResults'].map do |it|
42
99
  {result: it['result'],
43
100
  expectation: parse_expectation(it['expectation'])}
44
101
  end
@@ -54,4 +111,4 @@ module Mumukit
54
111
  end
55
112
  end
56
113
  end
57
- end
114
+ end
@@ -1,3 +1,3 @@
1
1
  module Mumukit
2
- VERSION = '2.9.0'
2
+ VERSION = '2.10.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.9.0
4
+ version: 2.10.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: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0.46'
167
+ - !ruby/object:Gem::Dependency
168
+ name: mumukit-inspection
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 2.1.0
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.1.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: mumukit-core
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -284,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
298
  version: '0'
285
299
  requirements: []
286
300
  rubyforge_project:
287
- rubygems_version: 2.6.12
301
+ rubygems_version: 2.6.11
288
302
  signing_key:
289
303
  specification_version: 4
290
304
  summary: Mumuki Test Server Development Kit