Class: Mumukit::Templates::MulangExpectationsHook
- Inherits:
-
FileHook
- Object
- Hook
- FileHook
- Mumukit::Templates::MulangExpectationsHook
show all
- Defined in:
- lib/mumukit/templates/mulang_expectations_hook.rb
Constant Summary
collapse
- LOGIC_SMELLS =
%w(UsesCut UsesFail UsesUnificationOperator HasRedundantReduction)
- FUNCTIONAL_SMELLS =
%w(HasRedundantParameter HasRedundantGuards)
- OBJECT_ORIENTED_SMELLS =
%w(DoesNullTest ReturnsNull)
- IMPERATIVE_SMELLS =
%w(HasRedundantLocalVariableReturn HasAssignmentReturn)
- EXPRESSIVENESS_SMELLS =
%w(HasTooShortBindings HasWrongCaseBindings HasMisspelledBindings)
- GENERIC_SMELLS =
%w(IsLongCode HasCodeDuplication HasRedundantLambda HasRedundantIf DoesTypeTest HasRedundantBooleanComparison)
Instance Attribute Summary
Attributes inherited from FileHook
#request
Attributes inherited from Hook
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from FileHook
#cleanup_raw_result, #compile, isolated, line_number_offset, mashup, #masked_tempfile_path, metatested, #run!, structured
#create_tempfile, #mask_tempfile_references, #with_tempfile, #write_tempfile!
Methods inherited from Hook
#env, #initialize, #logger, #method_missing, #should_forward_to_config?, stateful_through, #t
#content_type
Constructor Details
This class inherits a constructor from Mumukit::Hook
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Mumukit::Hook
Class Method Details
.include_smells(value = true) ⇒ Object
117
118
119
120
121
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 117
def self.include_smells(value=true)
if value
include Mumukit::Templates::WithCodeSmells
end
end
|
Instance Method Details
#command_line(filename) ⇒ Object
19
20
21
22
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 19
def command_line(filename)
"cat #{filename} | #{mulang_path} -s 2>&1"
end
|
#compile_content(content) ⇒ Object
95
96
97
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 95
def compile_content(content)
content
end
|
#compile_expectation(expectation) ⇒ Object
99
100
101
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 99
def compile_expectation(expectation)
Mumukit::Inspection::Expectation.parse(expectation).as_v2.to_h
end
|
#compile_expectations_and_exceptions(request) ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 77
def compile_expectations_and_exceptions(request)
expectations = []
exceptions = []
request[:expectations].each do |it|
fill_expectations_and_excetions it.deep_symbolize_keys, expectations, exceptions
end
[expectations, exceptions]
end
|
#compile_file_content(request) ⇒ Object
30
31
32
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 30
def compile_file_content(request)
compile_json_file_content(request).to_json
end
|
#compile_json_file_content(request) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 34
def compile_json_file_content(request)
expectations, exceptions = compile_expectations_and_exceptions request
{
sample: compile_sample(request),
spec: {
expectations: expectations,
smellsSet: {
tag: 'AllSmells',
exclude: (exceptions + default_smell_exceptions)
},
domainLanguage: domain_language
}
}
end
|
#compile_sample(request) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 61
def compile_sample(request)
compiled_content = compile_content(request[:content])
if language == 'Mulang'
{
tag: 'MulangSample',
ast: compiled_content
}
else
{
tag: 'CodeSample',
language: language,
content: compiled_content
}
end
end
|
#default_smell_exceptions ⇒ Object
57
58
59
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 57
def default_smell_exceptions
[]
end
|
#domain_language ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 49
def domain_language
{
caseStyle: "CamelCase",
minimumIdentifierSize: 3,
jargon: []
}
end
|
#fill_expectations_and_excetions(expectation, expectations, exceptions) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 86
def fill_expectations_and_excetions(expectation, expectations, exceptions)
inspection = expectation[:inspection]
if inspection&.start_with? 'Except:'
exceptions << inspection[7..-1]
else
expectations << compile_expectation(expectation)
end
end
|
#parse_expectation(expectation) ⇒ Object
113
114
115
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 113
def parse_expectation(expectation)
expectation.deep_symbolize_keys.except(:tag)
end
|
#parse_response(response) ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 103
def parse_response(response)
if response['tag'] == 'AnalysisFailed'
raise Mumukit::CompilationError, response['reason']
end
response['expectationResults'].map do |it|
{result: it['result'],
expectation: parse_expectation(it['expectation'])}
end
end
|
#post_process_file(file, result, status) ⇒ Object
24
25
26
27
28
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 24
def post_process_file(file, result, status)
parse_response JSON.pretty_parse(result)
rescue JSON::ParserError
raise Mumukit::CompilationError, "Can not handle mulang results #{result}"
end
|
#tempfile_extension ⇒ Object
15
16
17
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 15
def tempfile_extension
'.json'
end
|