# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved. # License:: LGPL # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/SubCmd.rb 24394 2006-07-10T07:38:58.276210Z ertai $ module Uttk module Strategies # I run a sub Uttk or an another program that can behave like it. class SubCmd < Strategy include Concrete def prologue super hooker = StrategyHooker.new @symtbl, @log, @env @runner = OCmd::Runners::Popen.new.hooker_subscribe hooker @command = @symtbl[:uttk].to_ocmd @command.dir = @symtbl[:pwd] @command.input = @input @command += @args.to_ocmd_args @command << '-F' << 'Path' << '--dump-status' end protected :prologue def run_impl @data = @command.run @runner @run_impl_status = nil root_path = @log.path YAML.load_from_io @data.output do |notification| case notification when Array path, leaf = notification @log.update(:new_leaf, root_path + path, leaf) when Status @run_impl_status = notification else raise_error 'bad sub commad output' end end @data.waitpid end protected :run_impl def assertion @data_error_contents = @data.error.read ref = { :exit => (/^[02]$/) } matcher_result = command_matcher[UM::StreamMatcher, ref, @data] raise_error 'bad exit status' if matcher_result.failure? raise_error 'bad status output' unless @run_impl_status.is_a? Status raise_error 'uttk stderr not empty' unless @data_error_contents.empty? @status = @run_impl_status raise_status @status end protected :assertion def abort_hook @runner.abort @data if @runner and defined? @data super end protected :abort_hook def error_hook if defined? @data @log.my_stdout = @data.output.to_s_for_uttk_log unless @data.output.nil? if defined? @data_error_contents and not @data_error_contents.empty? @log.my_stderr = @data_error_contents.to_s_for_uttk_log end @log.my_exit = @data.status.exitstatus unless @data.status.nil? end super end protected :error_hook def epilogue @data.clean if defined? @data super end protected :epilogue attribute :args, 'the arguments for the command', [Array, String, Numeric] attribute :input, 'the input reference', :invisible, nil attribute :env, 'environment variables', Hash do {} end end # class SubCmd end # module Strategies end # module Uttk