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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8a44729b686db8ec1bee4e049aa6ed466e80a764c2d199c3cdc37c4c6c49fe0
4
- data.tar.gz: 8ebe718ca780b84b09eccc38b5aba09ec751ac3462452c08a36b72e6309545c1
3
+ metadata.gz: 9c61f8cf6afdbca262d6e5b7277a5c743713e8562fa5a26402f6a0953427f68c
4
+ data.tar.gz: c373a4a25da4eea55906629a23232dcad8bfcccc1592e2eeeb422c607b4b370b
5
5
  SHA512:
6
- metadata.gz: b7cba2ac3824aacfd7bd82c346377f174ba6f77fab1415d05713ce3aaf9806d80d3696b39ab80b9b1f787d46613a750778f42ba614d075ff466d9bd871918a71
7
- data.tar.gz: 0772718ef25c9fb8c98f2798127b6f2fe240083f71d7ca2c39e167d32cc7e5ca5e51730c7440dce303c51d24da64382db6bb643c3bd50479828ce4e5b4a25891
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
@@ -4,7 +4,7 @@ class PhpMetadataHook < Mumukit::Hook
4
4
  language: {
5
5
  name: 'php',
6
6
  icon: {type: 'devicon', name: 'php'},
7
- version: 'v1.0.0',
7
+ version: 'v1.1.0',
8
8
  extension: 'php',
9
9
  ace_mode: 'php'
10
10
  },
@@ -1,4 +1,4 @@
1
- class PhpFileHook < Mumukit::Templates::FileHook
1
+ class PhpFileHook < Mumukit::Templates::MultiFileHook
2
2
  isolated true
3
3
 
4
4
  def tempfile_extension
@@ -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.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
@@ -1,18 +1,16 @@
1
- class PhpTestHook < PhpFileHook
2
- structured true
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 command_line(filename)
9
- "phpunit --testdox #{filename}"
10
- end
6
+ def run!(request)
7
+ result = request.result[:test]
11
8
 
12
- def post_process_file(file, result, status)
13
- return [result.strip, :errored] unless result.include? TEST_NAME
9
+ unless result.include? TEST_NAME
10
+ return [mask_tempfile_references(result.strip), :errored]
11
+ end
14
12
 
15
- super file, result, status
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
@@ -1,3 +1,3 @@
1
1
  module PhpVersionHook
2
- VERSION = '1.0.0'
2
+ VERSION = '1.4.0'
3
3
  end
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.0.0
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: 2018-08-27 00:00:00.000000000 Z
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.21'
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.21'
26
+ version: '2.38'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
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
- rubyforge_project:
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