class MxxRu::BinaryUnittestTarget

Class describing a target, which is unit-test binary application.

The idea is, that there is project file, which controls the build process of unit-test application. In that project file target object is created, inherited from MxxRu::BinaryTarget. To initialize unit-test it's required to create one more file, where target object of MxxRu::BinaryUnittestTarget class is created. For example:

File to compile unit-test.

MxxRu::setup_target(
  MxxRu::Cpp::ExeTarget.new( "test/pack/prj.rb" ) {
    ...
  }
)

File to run unit-test.

MxxRu::setup_target(
  MxxRu::BinaryUnittestTarget.new( 
    "test/pack/ut.rb",
    "test/pack/prj.rb ) )

File to use unit-test.

MxxRu::setup_target(
  MxxRu::Cpp::CompositeTarget.new( MxxRu::BUILD_ROOT ) {
    required_prj( "some/project/prj.rb" )
    required_prj( "test/pack/ut.rb" )
  }
)

Constants

Must_be_one_target_name_ex

Exception, thrown if subordinated project created more then one result name.

Attributes

mxx_build_state[R]

Attribute, showing that build method was already executed.

mxx_target_project[R]

Target, responsible for build of unit-test application.

Public Class Methods

new( a_alias, a_target_project ) click to toggle source

Constructor.

a_alias

Self alias.

a_target_project

Project, responsible for build of unit-test application.

Calls superclass method MxxRu::AbstractTarget::new
# File lib/mxx_ru/binary_unittest.rb, line 88
def initialize( a_alias, a_target_project )
  super( a_alias )

  @mxx_build_state = nil

  @mxx_target_project = required_prj( a_target_project )

  # By default the expected result of binary command is zero.
  # Kernel#system will return 'true' in that case.
  # In the case of NegativeBinaryUnittestTarget this value
  # must be changed to 'false'
  @expected_system_retval = true
end

Public Instance Methods

build() click to toggle source

Build subordinated project and run it.

If unit-test application returns result, other then 0, exception is thrown.

# File lib/mxx_ru/binary_unittest.rb, line 106
def build
  if !@mxx_build_state
    @mxx_target_project.build

    # Determining application name.
    full_names = @mxx_target_project.mxx_full_targets_names
    if 1 != full_names.size
      raise MustBeOneTargetNameEx.new( full_names )
    end

    # In dry-run do not actually execute anything.
    if !MxxRu::Util::Mode.instance.is_dry_run
      puts "running unit test: #{full_names[0]}..."
      if @expected_system_retval != system( full_names[ 0 ] )
        puts "\n\nunit test '#{full_names[0]}' FAILED! #{$?}"
        raise BuildEx.new( full_names[ 0 ], $? )
      end
    end

    @mxx_build_state = TargetState.new( TargetState::REBUILT )
  end

  return @mxx_build_state
end
clean() click to toggle source

Project cleanup.

Just execute clean method from subordinated project.

# File lib/mxx_ru/binary_unittest.rb, line 134
def clean
  @mxx_target_project.clean
end
reset() click to toggle source

Reset build state.

# File lib/mxx_ru/binary_unittest.rb, line 139
def reset
  @mxx_target_project.reset
  @mxx_build_state = nil
end