Module: Rutema::Elements::MSTest
- Defined in:
- lib/rutema/elements/win32.rb
Overview
Elements to drive MSTest
Instance Method Summary collapse
-
#element_mstest(step) ⇒ Object
Calls an MSTest assembly.
Instance Method Details
#element_mstest(step) ⇒ Object
Calls an MSTest assembly.
Requires the attribute assembly pointing to the assembly to execute. Path can be relative to the specification file.
Configuration
Requires a configuration.tool entry with :name=>“mstest” and a :configuration entry pointing to a hash containing the configuration parameters.
Configuration parameters are: :path - the path to the mstest utility. Required :shared_path - a :local=>“localpath”,:share=>“sharepath” entry. Optional :assembly_root - the path relative to which the assembly paths are calculated. If it’s not defined then the paths are calculated relative to the specification file. Optional
Example Configuration Entry
configuration.tool=:name=>“mstest”,:configuration=>{:path=>“/to/mstest.exe”,assembly_root=>“c:/assemblies”}
Extras
The shared_path hash is a workaround for calling assemblies when the current working directory is on a shared drive (i.e. when running certain tasks in a TFS build)
An example will illustrate it’s usage better:
:share=>“//host/tests”,:local=>“c:/tests” will result in :share being substituted with :local on the assembly pathname so \hoststestsassembly.dll becomes c:testsassembly.dll
Note that entries should be defined with ‘/’ instead of ‘'.
Examples
<mstest assembly=“tests.dll”/>
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rutema/elements/win32.rb', line 107 def element_mstest step raise Rutema::ParserError,"Missing required attribute 'assembly'" unless step.has_assembly? raise Rutema::ParserError,"Missing tool configuration for mstest (no configuration.tool entry)" unless @configuration.tools.mstest && @configuration.tools.mstest[:configuration] cfg=@configuration.tools.mstest[:configuration].dup raise Rutema::ParserError,"Cannot find mstest in '#{@configuration.tools.mstest[:path]}'" unless File.exists?(cfg[:path]) #if there is an assembly root defined than calculate the paths relative to that if cfg[:assembly_root] raise Rutema::ParserError, "assembly_root entry '#{cfg[:assembly_root]}' defined for mstest does not exist. Error in the configuration for mstest steps" unless File.exists?(cfg[:assembly_root]) assembly_path=File.(File.join(cfg[:assembly_root],step.assembly)) else assembly_path=File.(step.assembly) end #check that the assembly exists first raise Rutema::ParserError,"Cannot find assembly file '#{assembly_path}' in mstest step" unless File.exists?(assembly_path) #check to see if we apply the workaround if cfg[:shared_path] tfsbuild=cfg[:shared_path] raise Rutema::ParserError,"Missing :share key for tfsbuild configuration" unless shared_path[:share] raise Rutema::ParserError,"Missing :local key for tfsbuild configuration" unless shared_path[:local] @logger.debug("Shared path manipulation (#{shared_path[:share]}=>#{shared_path[:local]}") @logger.debug("Assembly path is '#{assembly_path}'") assembly_path.gsub!(tfsbuild[:share],tfsbuild[:local]) end #make the path windows compatible assembly_path.gsub!('/',"\\\\") #create the command line and the command instance cmdline="\"#{cfg[:path]}\" /testcontainer:\"#{assembly_path}\"" @logger.debug("Parsed mstest call as '#{cmdline}'") step.cmd=Patir::ShellCommand.new(:cmd=>cmdline,:working_directory=>File.dirname(assembly_path)) return step end |