mumukit 2.28.1 → 2.29.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: 14b2d5496f455caaf94529b6b558805e7dcd5a47b3a5d3995fbf025bf138b5ca
4
- data.tar.gz: 0755adc216b5ac1b3d9915575b5460807cd5cfcb8ba92cfff6a1912c14567ee2
3
+ metadata.gz: 3a827027f338d223865479f6fbd0bbc8ca7f36f52caf20f3402e08c749e0b3f7
4
+ data.tar.gz: 5208a95b1fe08adc9864cd0ec0b1dcdd12e6e91fcaf701664a1b9a5a52e1c08c
5
5
  SHA512:
6
- metadata.gz: b10d93420dc619acf65d42525acd7079c423a4c404a00894c3d7b2a4f6f719e0816470c2170df32fcaf0d9c13fcb03f93d36a65a6b3718ac0bc18d67a5999b3f
7
- data.tar.gz: 8e3f3023b3a46aa4806f1094d668874d924385303400eef3fe9424c3c9cad0afa35606f57860bc1f4d48d90392551c3097167eee5a2232d318ec664d72ed46b6
6
+ metadata.gz: 4fdd7cead0cf6d3d21f1dd89a65a85097c7c0576151e97db14b8d82346559fe0e0c0d257d26811bece79fe3b6cc70aa8117b453cb30b65b74d712f42d56745b9
7
+ data.tar.gz: 7d34da4a77324f5aaeedc0e3162b8e54902b423e14e7c0d830fbf51d76d956e73da28a3f650d260209f6462d0bc2e7a418e06bcd7bf5c371af1727cc03e91b14
data/lib/mumukit.rb CHANGED
@@ -53,6 +53,7 @@ end
53
53
 
54
54
  require 'mumukit/content_type'
55
55
 
56
+ require_relative 'mumukit/string'
56
57
  require_relative 'mumukit/version'
57
58
  require_relative 'mumukit/env'
58
59
  require_relative 'mumukit/cookie'
@@ -7,12 +7,11 @@ module Mumukit
7
7
  attr_accessor :container
8
8
 
9
9
  def configure!(*files)
10
-
11
10
  filenames = files.map { |it| File.absolute_path(it.path) }
12
- dirnames = filenames.map { |it| Pathname.new(it).dirname }
11
+ dirnames = filenames.map { |it| Pathname.new(it).dirname }.uniq
13
12
 
14
13
  binds = dirnames.map { |it| "#{it}:#{it}" }
15
- volumes = Hash[[dirnames.map { |it| [it, {}] }]]
14
+ volumes = Hash[dirnames.map { |it| [[it, {}]] }]
16
15
 
17
16
  command = yield(*filenames).split
18
17
 
@@ -28,9 +28,13 @@ class Mumukit::Server::TestServer
28
28
  end
29
29
 
30
30
  def parse_request_body(sinatra_request)
31
- JSON.parse(sinatra_request.body.read).tap do |it|
32
- I18n.locale = it['locale'] || :en
33
- end rescue {}
31
+ begin
32
+ parse_body(sinatra_request).tap do |it|
33
+ I18n.locale = it['locale'] || :en
34
+ end
35
+ rescue StandardError => e
36
+ raise StandardError.new("Error parsing request body. Cause: #{e}")
37
+ end
34
38
  end
35
39
 
36
40
  def test!(request)
@@ -120,4 +124,10 @@ class Mumukit::Server::TestServer
120
124
  def default_repo_url
121
125
  "https://github.com/mumuki/mumuki-#{Mumukit.runner_name}-runner"
122
126
  end
127
+
128
+ def parse_body(sinatra_request)
129
+ json = sinatra_request.body.read
130
+ return {} if json.empty?
131
+ JSON.parse json
132
+ end
123
133
  end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def sanitize_as_filename
3
+ self.gsub /[^0-9A-Z\.-]/i, '_'
4
+ end
5
+ end
@@ -15,6 +15,7 @@ require_relative './templates/with_code_smells'
15
15
  require_relative './templates/with_cookie'
16
16
 
17
17
  require_relative './templates/file_hook'
18
+ require_relative './templates/multi_file_hook'
18
19
  require_relative './templates/try_hook'
19
20
  require_relative './templates/expectations_hook'
20
21
  require_relative './templates/mulang_expectations_hook'
@@ -6,7 +6,7 @@ module Mumukit
6
6
  FUNCTIONAL_SMELLS = %w(HasRedundantParameter HasRedundantGuards)
7
7
  OBJECT_ORIENTED_SMELLS = %w(DoesNullTest ReturnsNull)
8
8
  IMPERATIVE_SMELLS = %w(HasRedundantLocalVariableReturn HasAssignmentReturn)
9
- EXPRESSIVENESS_SMELLS = %w(HasTooShortBindings HasWrongCaseBindings HasMisspelledBindings)
9
+ EXPRESSIVENESS_SMELLS = %w(HasTooShortIdentifiers HasWrongCaseIdentifiers HasMisspelledIdentifiers)
10
10
  GENERIC_SMELLS = %w(IsLongCode HasCodeDuplication HasRedundantLambda HasRedundantIf DoesTypeTest HasRedundantBooleanComparison HasEmptyIfBranches)
11
11
 
12
12
  required :language, 'You have to provide a Mulang-compatible language in order to use this hook'
@@ -0,0 +1,25 @@
1
+ require 'fileutils'
2
+
3
+ module Mumukit
4
+ class Templates::MultiFileHook < Templates::FileHook
5
+ include Mumukit::Templates::WithMultipleFiles
6
+
7
+ def compile(request)
8
+ return super unless has_files?(request)
9
+
10
+ self.request = request
11
+ write_tempdir! compile_file_content(request)
12
+ end
13
+
14
+ def run!(tempdir)
15
+ return super unless has_files?(request)
16
+
17
+ begin
18
+ result, status = run_files!(*tempdir.files)
19
+ post_process_file(tempdir.files, cleanup_raw_result(result), status)
20
+ ensure
21
+ FileUtils.rm_rf tempdir.dir
22
+ end
23
+ end
24
+ end
25
+ end
@@ -5,8 +5,10 @@ module Mumukit
5
5
  include Mumukit::WithCommandLine
6
6
  end
7
7
 
8
- def run_file!(file)
9
- run_command command_line(file.path)
8
+ def run_files!(*files)
9
+ run_command command_line(*files.map {|f| f.path})
10
10
  end
11
+
12
+ alias_method 'run_file!', 'run_files!'
11
13
  end
12
14
  end
@@ -1,11 +1,13 @@
1
1
  module Mumukit
2
2
  module Templates::WithIsolatedEnvironment
3
- def run_file!(file)
3
+ def run_files!(*files)
4
4
  env = Mumukit::IsolatedEnvironment.new
5
- env.configure!(file) { |filename| command_line(filename) }
5
+ env.configure!(*files) { |*filenames| command_line(*filenames) }
6
6
  env.run!
7
7
  ensure
8
8
  env.destroy!
9
9
  end
10
+
11
+ alias_method 'run_file!', 'run_files!'
10
12
  end
11
13
  end
@@ -1,6 +1,10 @@
1
1
  module Mumukit::Templates::WithMultipleFiles
2
2
  def files_of(request)
3
3
  raise 'You need to enable Mumukit.config.multifile first!' unless Mumukit.config.multifile
4
- request.content.is_a?(Hash) ? request.content : {}
4
+ has_files?(request) ? request.content : {}
5
+ end
6
+
7
+ def has_files?(request)
8
+ request.content.is_a?(Hash)
5
9
  end
6
10
  end
@@ -1,3 +1,3 @@
1
1
  module Mumukit
2
- VERSION = '2.28.1'
2
+ VERSION = '2.29.0'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'tempfile'
2
+ require 'tmpdir'
2
3
 
3
4
  module Mumukit
4
5
  module WithTempfile
@@ -16,6 +17,13 @@ module Mumukit
16
17
  end
17
18
  end
18
19
 
20
+ def write_tempdir!(files)
21
+ dir = Dir.mktmpdir
22
+ files.map do |filename, content|
23
+ File.open("#{dir}/#{filename.sanitize_as_filename}", 'w') { |file| file.write content; file }
24
+ end.try { |it| struct dir: dir, files: it }
25
+ end
26
+
19
27
  def with_tempfile
20
28
  file = create_tempfile
21
29
  yield file
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.28.1
4
+ version: 2.29.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-14 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -300,10 +300,12 @@ files:
300
300
  - lib/mumukit/server/response_builder.rb
301
301
  - lib/mumukit/server/test_pipeline.rb
302
302
  - lib/mumukit/server/test_server.rb
303
+ - lib/mumukit/string.rb
303
304
  - lib/mumukit/templates.rb
304
305
  - lib/mumukit/templates/expectations_hook.rb
305
306
  - lib/mumukit/templates/file_hook.rb
306
307
  - lib/mumukit/templates/mulang_expectations_hook.rb
308
+ - lib/mumukit/templates/multi_file_hook.rb
307
309
  - lib/mumukit/templates/multi_file_precompile_hook.rb
308
310
  - lib/mumukit/templates/try_hook.rb
309
311
  - lib/mumukit/templates/with_code_smells.rb
@@ -340,8 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
340
342
  - !ruby/object:Gem::Version
341
343
  version: '0'
342
344
  requirements: []
343
- rubyforge_project:
344
- rubygems_version: 2.7.8
345
+ rubygems_version: 3.0.2
345
346
  signing_key:
346
347
  specification_version: 4
347
348
  summary: Mumuki Test Server Development Kit