Class: MxxRu::BinaryUnittestTarget

Inherits:
AbstractTarget show all
Defined in:
lib/mxx_ru/binary_unittest.rb

Overview

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" )
  }
)

Direct Known Subclasses

NegativeBinaryUnittestTarget

Defined Under Namespace

Classes: MustBeOneTargetNameEx

Constant Summary collapse

Must_be_one_target_name_ex =

For compatibility with previous versions.

MustBeOneTargetNameEx

Instance Attribute Summary collapse

Attributes inherited from AbstractTarget

#mxx_full_targets_names, #mxx_generators, #mxx_required_prjs

Instance Method Summary collapse

Methods inherited from AbstractTarget

define_plural_form_method, #generator, #mxx_add_full_target_name, #prj_alias, #required_prj, run

Constructor Details

#initialize(a_alias, a_target_project) ⇒ BinaryUnittestTarget

Constructor.

a_alias

Self alias.

a_target_project

Project, responsible for build of unit-test application.



88
89
90
91
92
93
94
95
96
97
98
99
100
# 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

Instance Attribute Details

#mxx_build_stateObject (readonly)

Attribute, showing that build method was already executed.



81
82
83
# File 'lib/mxx_ru/binary_unittest.rb', line 81

def mxx_build_state
  @mxx_build_state
end

#mxx_target_projectObject (readonly)

Target, responsible for build of unit-test application.



79
80
81
# File 'lib/mxx_ru/binary_unittest.rb', line 79

def mxx_target_project
  @mxx_target_project
end

Instance Method Details

#buildObject

Build subordinated project and run it.

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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# 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

#cleanObject

Project cleanup.

Just execute clean method from subordinated project.



134
135
136
# File 'lib/mxx_ru/binary_unittest.rb', line 134

def clean
  @mxx_target_project.clean
end

#resetObject

Reset build state.



139
140
141
142
# File 'lib/mxx_ru/binary_unittest.rb', line 139

def reset
  @mxx_target_project.reset
  @mxx_build_state = nil
end