mumukit 2.25.0 → 2.26.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3ff9be27328e92ddbb2839b5516184611a2bc7668fc12104543c42e652fa1ad
|
4
|
+
data.tar.gz: a65d361bd7ca62cceb96c2612b2fb329ab3cf162a20465f90c43c607ef701fba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfcd703a70856249f859ce1f9b5a1e422a791558d2b0c3532d5a8b577043cdc09e7e67a4835c0ef76f0485dc6c112ebaa36ae8e0e6a1c5ebf54949564fa96102
|
7
|
+
data.tar.gz: daf555d8f5bd48540354e9b80b5554e4bcfa600b51aa7c6227513bb7310845de1d74833076854d91491bb7b1335b47964d4454a1a17c1c7cbca16d2f21f78763
|
data/lib/mumukit/templates.rb
CHANGED
@@ -16,5 +16,6 @@ require_relative './templates/with_cookie'
|
|
16
16
|
|
17
17
|
require_relative './templates/file_hook'
|
18
18
|
require_relative './templates/try_hook'
|
19
|
+
require_relative './templates/expectations_hook'
|
19
20
|
require_relative './templates/mulang_expectations_hook'
|
20
|
-
require_relative './templates/multi_file_precompile_hook'
|
21
|
+
require_relative './templates/multi_file_precompile_hook'
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'mumukit/inspection'
|
2
|
+
|
3
|
+
module Mumukit
|
4
|
+
class Templates::ExpectationsHook < Mumukit::Hook
|
5
|
+
SOURCE_EXPECTATION_EVALUATORS = {
|
6
|
+
'SourceRepeats' => lambda { |source, target| source.scan(target).count > 1 },
|
7
|
+
'SourceContains' => lambda { |source, target| source.include? target },
|
8
|
+
'SourceEquals' => lambda { |source, target| source == target },
|
9
|
+
'SourceEqualsIgnoreSpaces' => lambda { |source, target| source.delete(' ') == target.delete(' ') }
|
10
|
+
}
|
11
|
+
SOURCE_EXPECTATIONS = SOURCE_EXPECTATION_EVALUATORS.keys.flat_map { |it| [it, "Not:#{it}"] }
|
12
|
+
|
13
|
+
def compile(request)
|
14
|
+
{ request: request, expectations: compile_expectations(request) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def run!(spec)
|
18
|
+
spec[:expectations][:source].map { |it| it.evaluate spec[:request][:content] }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def compile_expectations(request)
|
24
|
+
expectations = {ast: [], source: [], exceptions: []}
|
25
|
+
request[:expectations].each do |it|
|
26
|
+
fill_expectations it.deep_symbolize_keys, expectations
|
27
|
+
end
|
28
|
+
expectations
|
29
|
+
end
|
30
|
+
|
31
|
+
def fill_expectations(expectation, expectations)
|
32
|
+
inspection = expectation[:inspection]
|
33
|
+
if inspection&.start_with? 'Except:'
|
34
|
+
expectations[:exceptions] << inspection[7..-1]
|
35
|
+
elsif SOURCE_EXPECTATIONS.any? { |it| inspection.starts_with? it }
|
36
|
+
expectations[:source] << compile_source_expectation(expectation)
|
37
|
+
else
|
38
|
+
expectations[:ast] << compile_expectation(expectation)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def compile_expectation(expectation)
|
43
|
+
Mumukit::Inspection::Expectation.parse(expectation).as_v2.to_h
|
44
|
+
end
|
45
|
+
|
46
|
+
def compile_source_expectation(expectation)
|
47
|
+
SourceExpectation.parse(expectation)
|
48
|
+
end
|
49
|
+
|
50
|
+
class SourceExpectation
|
51
|
+
def initialize(expectation, evaluator)
|
52
|
+
@expectation = expectation
|
53
|
+
@evaluator = evaluator
|
54
|
+
end
|
55
|
+
|
56
|
+
def evaluate(content)
|
57
|
+
{ result: evaluate_inspection(content), expectation: @expectation.to_h }
|
58
|
+
end
|
59
|
+
|
60
|
+
def inspection
|
61
|
+
@expectation.inspection
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.parse(expectation)
|
65
|
+
parsed = Mumukit::Inspection::Expectation.parse(expectation)
|
66
|
+
evaluator = parse_evaluator(parsed.inspection)
|
67
|
+
new parsed, evaluator
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def evaluate_inspection(content)
|
73
|
+
inspection.negated? ^ @evaluator.call(content, inspection.target.value)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.parse_evaluator(inspection)
|
77
|
+
SOURCE_EXPECTATION_EVALUATORS[inspection.type]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require 'mumukit/inspection'
|
2
1
|
require 'mulang'
|
3
2
|
|
4
3
|
module Mumukit
|
5
|
-
class Templates::MulangExpectationsHook < Mumukit::
|
4
|
+
class Templates::MulangExpectationsHook < Mumukit::Templates::ExpectationsHook
|
6
5
|
LOGIC_SMELLS = %w(UsesCut UsesFail UsesUnificationOperator HasRedundantReduction)
|
7
6
|
FUNCTIONAL_SMELLS = %w(HasRedundantParameter HasRedundantGuards)
|
8
7
|
OBJECT_ORIENTED_SMELLS = %w(DoesNullTest ReturnsNull)
|
@@ -12,18 +11,21 @@ module Mumukit
|
|
12
11
|
|
13
12
|
required :language, 'You have to provide a Mulang-compatible language in order to use this hook'
|
14
13
|
|
15
|
-
def
|
16
|
-
|
14
|
+
def run!(spec)
|
15
|
+
super(spec) + run_mulang_analysis(compile_mulang_analysis(spec[:request], spec[:expectations]))
|
16
|
+
end
|
17
|
+
|
18
|
+
def compile_mulang_analysis(request, expectations)
|
17
19
|
mulang_code(request).analysis(
|
18
|
-
expectations: expectations,
|
20
|
+
expectations: expectations[:ast],
|
19
21
|
smellsSet: {
|
20
22
|
tag: 'AllSmells',
|
21
|
-
exclude: (exceptions + default_smell_exceptions)
|
23
|
+
exclude: (expectations[:exceptions] + default_smell_exceptions)
|
22
24
|
},
|
23
25
|
domainLanguage: domain_language)
|
24
26
|
end
|
25
27
|
|
26
|
-
def
|
28
|
+
def run_mulang_analysis(analysis)
|
27
29
|
parse_response Mulang.analyse(analysis)
|
28
30
|
rescue JSON::ParserError
|
29
31
|
raise Mumukit::CompilationError, "Can not handle mulang results for analysis #{analysis}"
|
@@ -50,32 +52,10 @@ module Mumukit
|
|
50
52
|
language == 'Mulang' ? Mulang::Language::External.new : Mulang::Language::Native.new(language)
|
51
53
|
end
|
52
54
|
|
53
|
-
def compile_expectations_and_exceptions(request)
|
54
|
-
expectations = []
|
55
|
-
exceptions = []
|
56
|
-
request[:expectations].each do |it|
|
57
|
-
fill_expectations_and_excetions it.deep_symbolize_keys, expectations, exceptions
|
58
|
-
end
|
59
|
-
[expectations, exceptions]
|
60
|
-
end
|
61
|
-
|
62
|
-
def fill_expectations_and_excetions(expectation, expectations, exceptions)
|
63
|
-
inspection = expectation[:inspection]
|
64
|
-
if inspection&.start_with? 'Except:'
|
65
|
-
exceptions << inspection[7..-1]
|
66
|
-
else
|
67
|
-
expectations << compile_expectation(expectation)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
55
|
def compile_content(content)
|
72
56
|
content
|
73
57
|
end
|
74
58
|
|
75
|
-
def compile_expectation(expectation)
|
76
|
-
Mumukit::Inspection::Expectation.parse(expectation).as_v2.to_h
|
77
|
-
end
|
78
|
-
|
79
59
|
def parse_response(response)
|
80
60
|
if response['tag'] == 'AnalysisFailed'
|
81
61
|
raise Mumukit::CompilationError, response['reason']
|
data/lib/mumukit/version.rb
CHANGED
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.
|
4
|
+
version: 2.26.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: 2018-
|
11
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -301,6 +301,7 @@ files:
|
|
301
301
|
- lib/mumukit/server/test_pipeline.rb
|
302
302
|
- lib/mumukit/server/test_server.rb
|
303
303
|
- lib/mumukit/templates.rb
|
304
|
+
- lib/mumukit/templates/expectations_hook.rb
|
304
305
|
- lib/mumukit/templates/file_hook.rb
|
305
306
|
- lib/mumukit/templates/mulang_expectations_hook.rb
|
306
307
|
- lib/mumukit/templates/multi_file_precompile_hook.rb
|