mumuki-php-runner 1.0.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/expectations_hook.rb +41 -0
- data/lib/metadata_hook.rb +1 -1
- data/lib/php_file_hook.rb +1 -1
- data/lib/php_runner.rb +4 -1
- data/lib/precompile_hook.rb +59 -0
- data/lib/test_hook.rb +12 -26
- data/lib/version.rb +1 -1
- metadata +29 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c61f8cf6afdbca262d6e5b7277a5c743713e8562fa5a26402f6a0953427f68c
|
4
|
+
data.tar.gz: c373a4a25da4eea55906629a23232dcad8bfcccc1592e2eeeb422c607b4b370b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c714e696ee6072975ac4d256190d381d07695ad062f3dd107f74fa3ad0fd30d59ea97141fae6d1e5f0b5e6102a7ec24a91e94f7730b02b7f8efea1503a11b7
|
7
|
+
data.tar.gz: cc73db8cf9fc469964f6d01adf85ac6ef9704b40999827124ca81cfca7c8ca69b6524a0e02cfbdfc3b03cee73c87d88804d7564e9b1199a20bd29f6babe5bacb
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'mulang/php'
|
2
|
+
|
3
|
+
class PhpExpectationsHook < Mumukit::Templates::MulangExpectationsHook
|
4
|
+
SEPARATOR = '==> JSON dump:'
|
5
|
+
|
6
|
+
include_smells true
|
7
|
+
|
8
|
+
def language
|
9
|
+
'Mulang'
|
10
|
+
end
|
11
|
+
|
12
|
+
def mulang_code(request)
|
13
|
+
result = request.result[:ast]
|
14
|
+
|
15
|
+
Mulang::Code.new(mulang_language, to_mulang_ast(result))
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_mulang_ast(output)
|
19
|
+
unless output.include? SEPARATOR
|
20
|
+
return ['Unable to get Mulang AST - Command failed!', :errored]
|
21
|
+
end
|
22
|
+
|
23
|
+
json = output.split(SEPARATOR).last
|
24
|
+
ast = JSON.parse json, symbolize_names: true
|
25
|
+
|
26
|
+
Mulang::PHP.parse(ast)
|
27
|
+
rescue => e
|
28
|
+
raise Mumukit::CompilationError, e
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_smell_exceptions
|
32
|
+
LOGIC_SMELLS + FUNCTIONAL_SMELLS + OBJECT_ORIENTED_SMELLS
|
33
|
+
end
|
34
|
+
|
35
|
+
def domain_language
|
36
|
+
{
|
37
|
+
minimumIdentifierSize: 3,
|
38
|
+
jargon: []
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
data/lib/metadata_hook.rb
CHANGED
data/lib/php_file_hook.rb
CHANGED
data/lib/php_runner.rb
CHANGED
@@ -2,11 +2,14 @@ require 'mumukit'
|
|
2
2
|
|
3
3
|
Mumukit.runner_name = 'php'
|
4
4
|
Mumukit.configure do |config|
|
5
|
-
config.docker_image = 'mumuki/mumuki-php-worker:1.
|
5
|
+
config.docker_image = 'mumuki/mumuki-php-worker:1.5'
|
6
|
+
config.multifile = true
|
6
7
|
end
|
7
8
|
|
8
9
|
require_relative './version'
|
9
10
|
require_relative './metadata_hook'
|
10
11
|
require_relative './php_file_hook'
|
12
|
+
require_relative './precompile_hook'
|
11
13
|
require_relative './test_hook'
|
14
|
+
require_relative './expectations_hook'
|
12
15
|
require_relative './query_hook'
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class PhpPrecompileHook < PhpFileHook
|
2
|
+
BATCH_SEPARATOR = "\n/* ---Mumuki-Batch-Separator--- */\n"
|
3
|
+
RESULTS_SEPARATOR = "\n/* ---Mumuki-Results-Separator--- */\n"
|
4
|
+
|
5
|
+
def command_line(*filenames)
|
6
|
+
"run-tests-and-get-ast #{filenames.join(' ')}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def compile(request)
|
10
|
+
return request unless request[:query].nil?
|
11
|
+
|
12
|
+
files = super request
|
13
|
+
struct request.to_h.merge result: run!(files)
|
14
|
+
end
|
15
|
+
|
16
|
+
def compile_file_content(request)
|
17
|
+
test_content = compile_test_content request
|
18
|
+
|
19
|
+
if has_files?(request)
|
20
|
+
ast_content = request.content.values.join("\n")
|
21
|
+
add_php_tags(test_content).merge('submission_ast.json' => add_php_tag(ast_content))
|
22
|
+
else
|
23
|
+
add_php_tag(test_content) + BATCH_SEPARATOR + add_php_tag(request.content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def post_process_file(_file, result, status)
|
28
|
+
parts = result.split RESULTS_SEPARATOR
|
29
|
+
|
30
|
+
{ test: parts.first, ast: parts.last }
|
31
|
+
end
|
32
|
+
|
33
|
+
def compile_test_content(request)
|
34
|
+
test = <<-EOF
|
35
|
+
declare(strict_types=1);
|
36
|
+
|
37
|
+
#{request.extra}
|
38
|
+
#{has_files?(request) ? '' : request.content}
|
39
|
+
|
40
|
+
use PHPUnit\\Framework\\TestCase;
|
41
|
+
|
42
|
+
final class #{PhpTestHook::TEST_NAME}Test extends TestCase {
|
43
|
+
#{request.test.lines.map {|it| ' ' + it}.join}
|
44
|
+
}
|
45
|
+
EOF
|
46
|
+
|
47
|
+
has_files?(request) ?
|
48
|
+
files_of(request).merge("#{PhpTestHook::TEST_NAME.downcase}.php" => test) :
|
49
|
+
test
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_php_tags(files)
|
53
|
+
Hash[files.map{|name, content| [name, add_php_tag(content)] } ]
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_php_tag(content)
|
57
|
+
"<?php\n#{content}"
|
58
|
+
end
|
59
|
+
end
|
data/lib/test_hook.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
class PhpTestHook <
|
2
|
-
|
3
|
-
|
4
|
-
TEST_NAME = 'AAAMumukiTestCaseAAA'
|
1
|
+
class PhpTestHook < Mumukit::Defaults::TestHook
|
2
|
+
TEST_NAME = 'MumukiSubmissionTest'
|
5
3
|
PASSED_REGEXP = /[✔☢] ([^\n]+)/
|
6
4
|
FAILED_REGEXP = /✘ ([^\n]+)\n *\│\n *│ ([^イ]+│ \n )/
|
7
5
|
|
8
|
-
def
|
9
|
-
|
10
|
-
end
|
6
|
+
def run!(request)
|
7
|
+
result = request.result[:test]
|
11
8
|
|
12
|
-
|
13
|
-
|
9
|
+
unless result.include? TEST_NAME
|
10
|
+
return [mask_tempfile_references(result.strip), :errored]
|
11
|
+
end
|
14
12
|
|
15
|
-
|
13
|
+
[to_structured_result(result)]
|
16
14
|
end
|
17
15
|
|
18
16
|
def to_structured_result(result)
|
@@ -22,22 +20,6 @@ class PhpTestHook < PhpFileHook
|
|
22
20
|
passed_tests.concat(failed_tests)
|
23
21
|
end
|
24
22
|
|
25
|
-
def compile_file_content(req)
|
26
|
-
<<-EOF
|
27
|
-
<?php
|
28
|
-
declare(strict_types=1);
|
29
|
-
|
30
|
-
#{req.extra}
|
31
|
-
#{req.content}
|
32
|
-
|
33
|
-
use PHPUnit\\Framework\\TestCase;
|
34
|
-
|
35
|
-
final class #{TEST_NAME}Test extends TestCase {
|
36
|
-
#{req.test.lines.map {|it| ' ' + it}.join}
|
37
|
-
}
|
38
|
-
EOF
|
39
|
-
end
|
40
|
-
|
41
23
|
private
|
42
24
|
|
43
25
|
def to_passed_result(regexp_groups)
|
@@ -50,4 +32,8 @@ EOF
|
|
50
32
|
|
51
33
|
[regexp_groups.first, 'failed', reason]
|
52
34
|
end
|
35
|
+
|
36
|
+
def mask_tempfile_references(string)
|
37
|
+
string.gsub /\/tmp\/tmp\.\w+/, 'solution.php'
|
38
|
+
end
|
53
39
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-php-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Alfonso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumukit
|
@@ -16,28 +16,48 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.38'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.38'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: mulang-php
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '1.7'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '3'
|
34
51
|
type: :development
|
35
52
|
prerelease: false
|
36
53
|
version_requirements: !ruby/object:Gem::Requirement
|
37
54
|
requirements:
|
38
|
-
- - "
|
55
|
+
- - ">="
|
39
56
|
- !ruby/object:Gem::Version
|
40
57
|
version: '1.7'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3'
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: rake
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,9 +121,11 @@ executables: []
|
|
101
121
|
extensions: []
|
102
122
|
extra_rdoc_files: []
|
103
123
|
files:
|
124
|
+
- lib/expectations_hook.rb
|
104
125
|
- lib/metadata_hook.rb
|
105
126
|
- lib/php_file_hook.rb
|
106
127
|
- lib/php_runner.rb
|
128
|
+
- lib/precompile_hook.rb
|
107
129
|
- lib/query_hook.rb
|
108
130
|
- lib/test_hook.rb
|
109
131
|
- lib/version.rb
|
@@ -126,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
148
|
- !ruby/object:Gem::Version
|
127
149
|
version: '0'
|
128
150
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 2.7.7
|
151
|
+
rubygems_version: 3.0.6
|
131
152
|
signing_key:
|
132
153
|
specification_version: 4
|
133
154
|
summary: PHP Runner for Mumuki
|