avm 0.22.0 → 0.25.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: '0165809370dba684b9d456d8d28447e0d8cf625b9abe8f15a6b2d47aae905518'
4
- data.tar.gz: f8f75c35fd20364008a777023f542cb505c4ee0774c093c1069d452a2656becf
3
+ metadata.gz: 7adb5354bca33e4cda4d7a67cbdbcb5d2c980b43b635dab278d086119039609e
4
+ data.tar.gz: b820f3d9c7b4123b8575d8aae380101ac354e719cc3178ee89b814c2eb2ea79d
5
5
  SHA512:
6
- metadata.gz: ba30dc2ecb69636de16b65c6b2dc2b51e2e7014dec33f7958d9b8451cf515435868176d40570693e7f61b7e56a9896e0c40da3e98ce9e2c770acb2d06c339661
7
- data.tar.gz: d54c9c0ba6c1fcbcd2f2dba2eff4fc360a300c0eccf6d801989a1f11eb44dd32ae740a6dc122768292dbc1a59e0c51773d2bf78770503d7ce51ccfa7bf91fe91
6
+ metadata.gz: ce8c195c08b8a4bddd504b9dcdceebaf502fc05183d20a4acaa17ccda90fb3f9d03fd9748055c1dbe087620dfb8d58eb0ac82248680c5d2e0b0db2152bcc7c5c
7
+ data.tar.gz: abde1646aad402efa68a35800eab3501839234cfa739d26197d12d43f11f27376ae42b45a991096bbb52ba8d4e4a98e60853556a47432e4158f4a2c9885e7f01
@@ -11,19 +11,27 @@ module Avm
11
11
  module Configuration
12
12
  CONFIGURATION_FILENAMES = %w[.avm.yml .avm.yaml].freeze
13
13
 
14
+ # @return [EacRubyUtils::Envs::Command, nil]
15
+ def configuration_value_to_env_command(value)
16
+ configuration_value_to_shell_words(value).if_present { |v| env.command(v).chdir(path) }
17
+ end
18
+
19
+ # @return [Array<String>, nil]
20
+ def configuration_value_to_shell_words(value)
21
+ return nil if value.blank?
22
+
23
+ value.is_a?(::Enumerable) ? value.map(&:to_s) : ::Shellwords.split(value.to_s)
24
+ end
25
+
14
26
  # @return [Array<String>, nil]
15
27
  def read_configuration_as_shell_words(key)
16
- configuration.entry(key).value.if_present do |v|
17
- v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v.to_s)
18
- end
28
+ configuration_value_to_shell_words(configuration.entry(key).value)
19
29
  end
20
30
 
21
31
  # Utility to read a configuration as a [EacRubyUtils::Envs::Command].
22
32
  # @return [EacRubyUtils::Envs::Command]
23
33
  def read_configuration_as_env_command(key)
24
- read_configuration_as_shell_words(key).if_present do |v|
25
- env.command(v).chdir(path)
26
- end
34
+ configuration_value_to_env_command(configuration.entry(key).value)
27
35
  end
28
36
 
29
37
  private
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/sources/base/subs_paths'
4
+ require 'eac_cli/runner_with/subcommands'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Sources
9
+ class Base
10
+ module Runners
11
+ # @return [Hash<String, EacCli::Runner>]
12
+ def extra_available_subcommands
13
+ extra_available_subcommands_from_runners_module
14
+ end
15
+
16
+ # @return [Hash<String, EacCli::Runner>]
17
+ def extra_available_subcommands_from_runners_module
18
+ self.class.ancestors.reverse.inject({}) do |a, e|
19
+ a.merge(RunnersFromModule.new(e).result)
20
+ end
21
+ end
22
+
23
+ class RunnersFromModule
24
+ enable_simple_cache
25
+ common_constructor :the_module
26
+
27
+ # @return [Hash<String, EacCli::Runner>]
28
+ def result
29
+ return {} if runners_module.blank?
30
+
31
+ ::EacCli::RunnerWith::Subcommands.subcommands_from_module(runners_module)
32
+ end
33
+
34
+ def runners_module_uncached
35
+ return nil if the_module.module_parent.blank?
36
+
37
+ begin
38
+ the_module.module_parent.const_get('Runners')
39
+ rescue ::NameError
40
+ nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,25 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/envs/command'
4
5
 
5
6
  module Avm
6
7
  module Sources
7
8
  class Base
8
9
  module Testing
9
- TEST_COMMAND_KEY = 'test.command'
10
+ DEFAULT_TEST_COMMANDS = {}.freeze
11
+ TEST_KEY = 'test'
12
+ TEST_COMMAND_KEY = "#{TEST_KEY}.command"
13
+ TEST_COMMANDS_KEY = "#{TEST_KEY}.commands"
10
14
 
11
15
  def configured_test_command
12
16
  read_configuration_as_env_command(TEST_COMMAND_KEY)
13
17
  end
14
18
 
15
- # @return [Avm::Sources::Tester]
16
- def tester
17
- tester_class.new(self)
19
+ # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
20
+ def configured_test_commands
21
+ configured_value_as_test_commands(configuration.entry(TEST_COMMANDS_KEY).value)
18
22
  end
19
23
 
20
- # @return [Class<Avm::Sources::Tester>
21
- def tester_class
22
- Avm::Sources::Tester
24
+ # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
25
+ def configured_value_as_test_commands(value)
26
+ return nil if value.blank?
27
+
28
+ [::EacRubyUtils::Envs::Command, ::Hash, ::Enumerable].each do |type|
29
+ next unless value.is_a?(type)
30
+
31
+ return send(
32
+ "configured_#{type.name.demodulize.variableize}_value_as_test_commands",
33
+ value
34
+ )
35
+ end
36
+
37
+ raise "Value for test commands should be a Hash or a Enumerable (Actual: #{value})"
38
+ end
39
+
40
+ # @return [Hash<String, EacRubyUtils::Envs::Command>]
41
+ def default_test_commands
42
+ DEFAULT_TEST_COMMANDS
43
+ end
44
+
45
+ # @return [Enumerable<EacRubyUtils::Envs::Command>]
46
+ def test_commands
47
+ configured_test_commands ||
48
+ configured_value_as_test_commands(configured_test_command)
49
+ default_test_commands
50
+ end
51
+
52
+ protected
53
+
54
+ def configured_command_value_as_test_commands(value)
55
+ configured_enumerable_value_as_test_commands([value])
56
+ end
57
+
58
+ def configured_enumerable_value_as_test_commands(value)
59
+ configured_hash_value_as_test_commands(
60
+ value.each_with_index.map { |v| ["test_#{v[1]}", v[0]] }.to_h
61
+ )
62
+ end
63
+
64
+ def configured_hash_value_as_test_commands(value)
65
+ value.map { |k, v| [k.to_s.strip, configuration_value_to_env_command(v)] }.to_h
23
66
  end
24
67
  end
25
68
  end
@@ -26,11 +26,6 @@ module Avm
26
26
  ::EacRubyUtils::Envs::LocalEnv.new
27
27
  end
28
28
 
29
- # @return [Hash<String, Class>]
30
- def extra_available_subcommands
31
- {}
32
- end
33
-
34
29
  # @return [Pathname]
35
30
  def relative_path
36
31
  return path if parent.blank?
@@ -8,6 +8,8 @@ module Avm
8
8
  module Sources
9
9
  module Tests
10
10
  class Builder
11
+ NO_TEST_TEST_NAME = 'no_test'
12
+
11
13
  require_sub __FILE__
12
14
  enable_immutable
13
15
 
@@ -44,6 +46,22 @@ module Avm
44
46
  create_units(main_source.subs)
45
47
  end
46
48
 
49
+ # @return [Avm::Sources::Tests::Single]
50
+ def create_source_no_test_unit(source)
51
+ ::Avm::Sources::Tests::Single.new(self, source, NO_TEST_TEST_NAME,
52
+ source.env.command('true'))
53
+ end
54
+
55
+ # @return [Array<Avm::Sources::Tests::Single>]
56
+ def create_source_units(source)
57
+ tests = source.test_commands
58
+ return create_source_no_test_unit(source) unless tests.any?
59
+
60
+ tests.map do |test_name, test_command|
61
+ ::Avm::Sources::Tests::Single.new(self, source, test_name, test_command)
62
+ end
63
+ end
64
+
47
65
  # @return [Avm::Sources::Tests::Single]
48
66
  def create_unit(source)
49
67
  ::Avm::Sources::Tests::Single.new(self, source)
@@ -51,7 +69,7 @@ module Avm
51
69
 
52
70
  # @return [Array<Avm::Sources::Tests::Single>]
53
71
  def create_units(sources)
54
- sources.map { |a_source| create_unit(a_source) }
72
+ sources.flat_map { |a_source| create_source_units(a_source) }
55
73
  end
56
74
 
57
75
  # @return [Avm::Sources::Tests::Single]
@@ -14,9 +14,8 @@ module Avm
14
14
  enable_simple_cache
15
15
  enable_speaker
16
16
 
17
- common_constructor :builder, :source
17
+ common_constructor :builder, :source, :test_name, :test_command
18
18
 
19
- delegate :logs, :result, to: :tester
20
19
  delegate :to_s, to: :id
21
20
 
22
21
  def failed?
@@ -25,11 +24,7 @@ module Avm
25
24
 
26
25
  # @return [String]
27
26
  def id
28
- if main?
29
- MAIN_SOURCE_ID
30
- else
31
- relative_path_from_main_source.to_s
32
- end
27
+ "#{main? ? MAIN_SOURCE_ID : relative_path_from_main_source}\##{test_name}"
33
28
  end
34
29
 
35
30
  def main?
@@ -47,8 +42,32 @@ module Avm
47
42
 
48
43
  private
49
44
 
50
- def tester_uncached
51
- source.tester
45
+ # @return [EacFs::Logs]
46
+ def logs_uncached
47
+ ::EacFs::Logs.new.add(:stdout).add(:stderr)
48
+ end
49
+
50
+ # @return [Avm::Sources::Tests::Result]
51
+ def result_uncached
52
+ if test_command.blank?
53
+ ::Avm::Sources::Tests::Result::NONEXISTENT
54
+ elsif run_test_command
55
+ ::Avm::Sources::Tests::Result::SUCESSFUL
56
+ else
57
+ ::Avm::Sources::Tests::Result::FAILED
58
+ end
59
+ end
60
+
61
+ def run_test_command
62
+ execute_command_and_log(test_command)
63
+ end
64
+
65
+ # @return [true, false]
66
+ def execute_command_and_log(command)
67
+ r = command.execute
68
+ logs[:stdout].write(r[:stdout])
69
+ logs[:stderr].write(r[:stderr])
70
+ r[:exit_code].zero?
52
71
  end
53
72
  end
54
73
  end
data/lib/avm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.22.0'
4
+ VERSION = '0.25.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-02 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.23'
19
+ version: '0.27'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.23.1
22
+ version: 0.27.6
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.23'
29
+ version: '0.27'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.23.1
32
+ version: 0.27.6
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: eac_docker
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -246,12 +246,12 @@ files:
246
246
  - lib/avm/sources/base/instance.rb
247
247
  - lib/avm/sources/base/locale.rb
248
248
  - lib/avm/sources/base/parent.rb
249
+ - lib/avm/sources/base/runners.rb
249
250
  - lib/avm/sources/base/subs.rb
250
251
  - lib/avm/sources/base/subs_paths.rb
251
252
  - lib/avm/sources/base/testing.rb
252
253
  - lib/avm/sources/configuration.rb
253
254
  - lib/avm/sources/configuration/rubocop.rb
254
- - lib/avm/sources/tester.rb
255
255
  - lib/avm/sources/tests.rb
256
256
  - lib/avm/sources/tests/builder.rb
257
257
  - lib/avm/sources/tests/performer.rb
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Sources
7
- class Tester
8
- enable_abstract_methods
9
- common_constructor :source
10
-
11
- abstract_methods :result, :logs
12
-
13
- # @return [EacFs::Logs]
14
- def logs
15
- raise_abstract_method __method__
16
- end
17
-
18
- # @return [Avm::Sources::Tests::Result]
19
- def result
20
- raise_abstract_method __method__
21
- end
22
- end
23
- end
24
- end