mumuki-php-runner 1.0.0 → 1.1.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: e8e53aafc19ead748877758997dde14238f71cb2049e786d432e616571c9d106
4
+ data.tar.gz: 966ec97d251cfe9111b8249fe2583970434f14fdd9c32658f02b3d06410b4fb1
5
5
  SHA512:
6
- metadata.gz: b7cba2ac3824aacfd7bd82c346377f174ba6f77fab1415d05713ce3aaf9806d80d3696b39ab80b9b1f787d46613a750778f42ba614d075ff466d9bd871918a71
7
- data.tar.gz: 0772718ef25c9fb8c98f2798127b6f2fe240083f71d7ca2c39e167d32cc7e5ca5e51730c7440dce303c51d24da64382db6bb643c3bd50479828ce4e5b4a25891
6
+ metadata.gz: 897e4a8a031a71d22d773259de72d92f6273316f8d02eb00de96c9f655921a43fee2ea7aece4ce20a3c57322587c81e4adfe63633da6202fbff2d06a1f8d7d26
7
+ data.tar.gz: 5373842d85ce7a476bf68235ee29050585046642c9c27f40ca7f88fc5a29e58b95dc5dcf02835f6d9df6d21206792cbc8413e4f83f7ae5589a67f83f6498de76
@@ -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
@@ -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
  },
data/lib/php_runner.rb CHANGED
@@ -2,11 +2,13 @@ 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.4'
6
6
  end
7
7
 
8
8
  require_relative './version'
9
9
  require_relative './metadata_hook'
10
10
  require_relative './php_file_hook'
11
+ require_relative './precompile_hook'
11
12
  require_relative './test_hook'
13
+ require_relative './expectations_hook'
12
14
  require_relative './query_hook'
@@ -0,0 +1,45 @@
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(filename)
6
+ "run-tests-and-get-ast #{filename}"
7
+ end
8
+
9
+ def compile(request)
10
+ return request unless request[:query].nil?
11
+
12
+ file = super request
13
+ struct request.to_h.merge result: run!(file)
14
+ end
15
+
16
+ def compile_file_content(request)
17
+ compile_test_content(request) + BATCH_SEPARATOR + compile_ast_content(request)
18
+ end
19
+
20
+ def post_process_file(_file, result, status)
21
+ parts = result.split RESULTS_SEPARATOR
22
+
23
+ { test: parts.first, ast: parts.last }
24
+ end
25
+
26
+ def compile_test_content(request)
27
+ <<-EOF
28
+ <?php
29
+ declare(strict_types=1);
30
+
31
+ #{request.extra}
32
+ #{request.content}
33
+
34
+ use PHPUnit\\Framework\\TestCase;
35
+
36
+ final class #{PhpTestHook::TEST_NAME}Test extends TestCase {
37
+ #{request.test.lines.map {|it| ' ' + it}.join}
38
+ }
39
+ EOF
40
+ end
41
+
42
+ def compile_ast_content(request)
43
+ "<?php\n#{request[:content]}"
44
+ end
45
+ end
data/lib/test_hook.rb CHANGED
@@ -1,18 +1,16 @@
1
- class PhpTestHook < PhpFileHook
2
- structured true
3
-
1
+ class PhpTestHook < Mumukit::Defaults::TestHook
4
2
  TEST_NAME = 'AAAMumukiTestCaseAAA'
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
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PhpVersionHook
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.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.1.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: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.21'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mulang-php
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -101,9 +115,11 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
118
+ - lib/expectations_hook.rb
104
119
  - lib/metadata_hook.rb
105
120
  - lib/php_file_hook.rb
106
121
  - lib/php_runner.rb
122
+ - lib/precompile_hook.rb
107
123
  - lib/query_hook.rb
108
124
  - lib/test_hook.rb
109
125
  - lib/version.rb