Sha256: 3c3cf7b888d0b66e2775c632c2fe749ef5bbdf73a97765132fd49a5e2b74f923

Contents?: true

Size: 1.74 KB

Versions: 34

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

require 'avm/sources/tests/result'
require 'eac_ruby_utils/core_ext'
require 'eac_fs/logs'

module Avm
  module Sources
    module Tests
      class Single
        MAIN_SOURCE_ID = '#main'

        compare_by :order_group, :id
        enable_simple_cache
        enable_speaker

        common_constructor :builder, :source, :test_name, :test_command

        delegate :to_s, to: :id

        def failed?
          result == ::Avm::Sources::Tests::Result::FAILED
        end

        # @return [String]
        def id
          "#{main? ? MAIN_SOURCE_ID : relative_path_from_main_source}##{test_name}"
        end

        def main?
          relative_path_from_main_source.to_s == '.'
        end

        def order_group
          main? ? 1 : 0
        end

        # @return [Pathname]
        def relative_path_from_main_source
          source.path.relative_path_from(builder.main_source.path)
        end

        private

        # @return [EacFs::Logs]
        def logs_uncached
          ::EacFs::Logs.new.add(:stdout).add(:stderr)
        end

        # @return [Avm::Sources::Tests::Result]
        def result_uncached
          if test_command.blank?
            ::Avm::Sources::Tests::Result::NONEXISTENT
          elsif run_test_command
            ::Avm::Sources::Tests::Result::SUCESSFUL
          else
            ::Avm::Sources::Tests::Result::FAILED
          end
        end

        def run_test_command
          execute_command_and_log(test_command)
        end

        # @return [true, false]
        def execute_command_and_log(command)
          r = command.execute
          logs[:stdout].write(r[:stdout])
          logs[:stderr].write(r[:stderr])
          r[:exit_code].zero?
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
avm-0.94.1 lib/avm/sources/tests/single.rb
eac_tools-0.98.0 sub/avm/lib/avm/sources/tests/single.rb
avm-0.94.0 lib/avm/sources/tests/single.rb
eac_tools-0.94.0 sub/avm/lib/avm/sources/tests/single.rb
avm-0.93.0 lib/avm/sources/tests/single.rb
eac_tools-0.92.0 sub/avm/lib/avm/sources/tests/single.rb
avm-0.92.0 lib/avm/sources/tests/single.rb
eac_tools-0.91.0 sub/avm/lib/avm/sources/tests/single.rb
avm-0.90.1 lib/avm/sources/tests/single.rb
eac_tools-0.87.1 sub/avm/lib/avm/sources/tests/single.rb
avm-0.90.0 lib/avm/sources/tests/single.rb
eac_tools-0.87.0 sub/avm/lib/avm/sources/tests/single.rb
avm-0.89.0 lib/avm/sources/tests/single.rb
eac_tools-0.86.12 sub/avm/lib/avm/sources/tests/single.rb
avm-0.88.0 lib/avm/sources/tests/single.rb
eac_tools-0.86.11 sub/avm/lib/avm/sources/tests/single.rb
avm-0.87.0 lib/avm/sources/tests/single.rb
eac_tools-0.86.8 sub/avm/lib/avm/sources/tests/single.rb
avm-0.86.2 lib/avm/sources/tests/single.rb
eac_tools-0.86.7 sub/avm/lib/avm/sources/tests/single.rb