uttk 0.3.6.1 → 0.4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/BESTOF +13 -0
  2. data/ChangeLog +19 -0
  3. data/MATRIX +6 -0
  4. data/NEWS +34 -4
  5. data/PITFALLS +13 -0
  6. data/Rakefile +19 -2
  7. data/SPEC.gemspec +18 -0
  8. data/SPEC.yml +21 -7
  9. data/bin/getopts/uttk.rb +23 -10
  10. data/lib/uttk.rb +16 -12
  11. data/lib/uttk/dumpers/Mail.rb +41 -0
  12. data/lib/uttk/dumpers/Yaml.rb +2 -2
  13. data/lib/uttk/filters/KeepSkipBased.rb +1 -1
  14. data/lib/uttk/generators/templates/loader.rb +1 -1
  15. data/lib/uttk/generators/templates/strategy-command.rb +72 -0
  16. data/lib/uttk/generators/templates/strategy.rb +4 -3
  17. data/lib/uttk/generators/templates/unit_test.rb +1 -1
  18. data/lib/uttk/loaders/Loader.rb +1 -1
  19. data/lib/uttk/loaders/Ruby.rb +1 -1
  20. data/lib/uttk/loaders/Yaml.rb +2 -2
  21. data/lib/uttk/logger/section_node.rb +1 -1
  22. data/lib/uttk/logger/severity.rb +1 -1
  23. data/lib/uttk/logger/to_uttk_log.rb +2 -2
  24. data/lib/uttk/logger/verbosity.rb +1 -1
  25. data/lib/uttk/logger_factory.rb +1 -1
  26. data/lib/uttk/status.rb +1 -1
  27. data/lib/uttk/strategies/Abort.rb +1 -1
  28. data/lib/uttk/strategies/Assert.rb +1 -1
  29. data/lib/uttk/strategies/Authors.rb +2 -2
  30. data/lib/uttk/strategies/Bootstrap.rb +38 -11
  31. data/lib/uttk/strategies/Checkout.rb +3 -2
  32. data/lib/uttk/strategies/Clean.rb +1 -1
  33. data/lib/uttk/strategies/Collection.rb +3 -3
  34. data/lib/uttk/strategies/Command.rb +95 -0
  35. data/lib/uttk/strategies/Composite/contents_eval.rb +1 -1
  36. data/lib/uttk/strategies/Configure.rb +34 -25
  37. data/lib/uttk/strategies/Error.rb +1 -1
  38. data/lib/uttk/strategies/Fail.rb +1 -1
  39. data/lib/uttk/strategies/HostSelector.rb +143 -0
  40. data/lib/uttk/strategies/Import.rb +2 -2
  41. data/lib/uttk/strategies/Iterate.rb +1 -1
  42. data/lib/uttk/strategies/JUnit.rb +1 -1
  43. data/lib/uttk/strategies/Jump.rb +81 -0
  44. data/lib/uttk/strategies/Make.rb +28 -58
  45. data/lib/uttk/strategies/Package.rb +5 -6
  46. data/lib/uttk/strategies/PackageCollection.rb +1 -1
  47. data/lib/uttk/strategies/Pass.rb +1 -1
  48. data/lib/uttk/strategies/RUnit.rb +63 -49
  49. data/lib/uttk/strategies/SignalCmd.rb +1 -1
  50. data/lib/uttk/strategies/Sleep.rb +1 -1
  51. data/lib/uttk/strategies/SqlQuery.rb +1 -1
  52. data/lib/uttk/strategies/Strategy.rb +153 -3
  53. data/lib/uttk/strategies/SubCmd.rb +51 -31
  54. data/lib/uttk/strategies/Suite.rb +1 -1
  55. data/lib/uttk/strategies/Test.rb +1 -1
  56. data/lib/uttk/strategies/{ProbabilityThreshold.rb → Threshold.rb} +3 -3
  57. data/lib/uttk/streams.rb +1 -1
  58. data/lib/uttk/streams/Diff.rb +1 -1
  59. data/lib/uttk/streams/Stream.rb +1 -1
  60. data/lib/uttk/version_id.rb +1 -1
  61. data/lib/uttk/weights/WExpr.rb +1 -1
  62. data/lib/uttk/weights/WFloat.rb +1 -1
  63. data/lib/uttk/weights/WMin.rb +1 -1
  64. data/lib/uttk/weights/Weight.rb +1 -1
  65. data/lib/www/images/opentriangle.gif +0 -0
  66. data/lib/www/images/triangle.gif +0 -0
  67. data/lib/www/stylesheets/uttk.css +167 -0
  68. data/misc/expandtab.rb +1 -1
  69. data/test/examples/students/mini-lib.yml +1 -1
  70. data/test/fixtures/binaries/segv +0 -0
  71. data/test/functional/base.yml +29 -0
  72. data/test/functional/cat.yml +2 -2
  73. data/test/functional/cmd.yml +5 -0
  74. data/test/functional/command.yml +14 -0
  75. data/test/functional/diff.yml +2 -2
  76. data/test/functional/env_cmd.yml +3 -3
  77. data/test/functional/exit.yml +1 -1
  78. data/test/functional/host_selector.yml +30 -0
  79. data/test/functional/iterate.yml +31 -37
  80. data/test/functional/jump.yml +34 -0
  81. data/test/functional/pkg.yml +1 -1
  82. data/test/functional/{probability_threshold.yml → threshold.yml} +2 -2
  83. data/test/functional/timeout.yml +1 -1
  84. data/test/functional/wc.yml +2 -2
  85. data/test/unit/dumpers/mail_test.rb +46 -0
  86. data/test/unit/filters/keep_skip_based_test.rb +1 -1
  87. data/test/unit/filters/text_filter_test.rb +1 -1
  88. metadata +258 -253
  89. data/test/fixtures/demo/command-tutorial/steps/1/check.yml +0 -5
  90. data/test/fixtures/demo/command-tutorial/steps/1/pluralizer.rb +0 -10
  91. data/test/fixtures/demo/command-tutorial/steps/2/bad_check.yml +0 -7
  92. data/test/fixtures/demo/command-tutorial/steps/2/check.yml +0 -7
  93. data/test/fixtures/demo/command-tutorial/steps/2/pluralizer.rb +0 -10
  94. data/test/fixtures/demo/command-tutorial/steps/3.1/check.yml +0 -12
  95. data/test/fixtures/demo/command-tutorial/steps/3/check.yml +0 -14
  96. data/test/fixtures/demo/command-tutorial/steps/4.1/bird.txt +0 -1
  97. data/test/fixtures/demo/command-tutorial/steps/4.1/check.yml +0 -12
  98. data/test/fixtures/demo/command-tutorial/steps/4/check.yml +0 -12
  99. data/test/fixtures/demo/command-tutorial/steps/4/pluralizer.rb +0 -12
  100. data/test/fixtures/demo/command-tutorial/steps/5.1/bird.txt +0 -1
  101. data/test/fixtures/demo/command-tutorial/steps/5.1/check.yml +0 -17
  102. data/test/fixtures/demo/command-tutorial/steps/5.1/pluralizer.rb +0 -17
  103. data/test/fixtures/demo/command-tutorial/steps/5/bird.txt +0 -1
  104. data/test/fixtures/demo/command-tutorial/steps/5/check.yml +0 -16
  105. data/test/fixtures/demo/command-tutorial/steps/5/pluralizer.rb +0 -16
  106. data/test/fixtures/demo/command-tutorial/steps/6.1/bird.txt +0 -1
  107. data/test/fixtures/demo/command-tutorial/steps/6.1/check.yml +0 -22
  108. data/test/fixtures/demo/command-tutorial/steps/6.1/pluralizer.rb +0 -17
  109. data/test/fixtures/demo/command-tutorial/steps/6/bird.txt +0 -1
  110. data/test/fixtures/demo/command-tutorial/steps/6/check.yml +0 -21
  111. data/test/fixtures/demo/command-tutorial/steps/6/pluralizer.rb +0 -17
  112. data/test/fixtures/demo/command-tutorial/steps/7/bird.txt +0 -1
  113. data/test/fixtures/demo/command-tutorial/steps/7/check.yml +0 -22
  114. data/test/fixtures/demo/command-tutorial/steps/7/pluralizer.rb +0 -17
@@ -1,7 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /fey/uttk/trunk/lib/uttk/strategies/Package.rb 8789 2005-09-27T14:49:49.088376Z ertai $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/Package.rb 24394 2006-07-10T07:38:58.276210Z ertai $
5
5
 
6
6
 
7
7
  module Uttk
@@ -54,14 +54,13 @@ module Uttk
54
54
 
55
55
  make = {}
56
56
 
57
- [ Make::Check, Make::DistCheck, Make::Install ].each do |step|
58
- step_name = step.target
59
- next if skip_step? step_name
57
+ %w[ check distcheck install ].each do |step|
58
+ next if skip_step? step
60
59
  create(Make) do |build|
61
- build.name = "Building #{step_name}"
60
+ build.name = "Building #{step}"
62
61
  build.target = step
63
62
  build.fatal = true
64
- make[step_name.to_sym] = build
63
+ make[step.to_sym] = build
65
64
  end
66
65
  end
67
66
 
@@ -1,7 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /fey/uttk/trunk/lib/uttk/strategies/PackageCollection.rb 8789 2005-09-27T14:49:49.088376Z ertai $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/PackageCollection.rb 8789 2005-09-27T14:49:49.088376Z ertai $
5
5
 
6
6
 
7
7
  module Uttk
@@ -1,7 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /fey/uttk/trunk/lib/uttk/strategies/Pass.rb 8778 2005-09-26T04:34:48.103938Z ertai $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/Pass.rb 8778 2005-09-26T04:34:48.103938Z ertai $
5
5
 
6
6
 
7
7
  module Uttk
@@ -1,7 +1,7 @@
1
1
  # Author:: Nicolas Despres <nicolas.despres@gmail.com>.
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/RUnit.rb 22102 2006-02-21T23:03:39.538964Z pouillar $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/RUnit.rb 24394 2006-07-10T07:38:58.276210Z ertai $
5
5
 
6
6
 
7
7
  require 'yaml'
@@ -55,64 +55,80 @@ module Uttk
55
55
  # strategy into the YAML input file of Uttk, there is another way that is
56
56
  # used in test/unit-suite.yml.
57
57
  #
58
- class RUnit < CmdBase
58
+ class RUnit < Strategy
59
59
  include Concrete
60
60
 
61
- protected
62
61
  def prologue
63
- @command = '<<ruby>> -- <<uttk-unit>> '
62
+ super
63
+ @runner = mk_system_runner
64
+ @command = '<<ruby>>'.to_ocmd << '--' << '<<uttk-unit>>'
64
65
  if @verbose
65
- @command += '--verbose '
66
+ @command << '--verbose'
66
67
  else
67
- @command += '--no-verbose '
68
- end
69
- @load_path.each { |x| @command += "-I #{x} " }
70
- @requires = [@requires] unless @requires.respond_to? :each
71
- @requires.each { |x| @command += "-r #{x} " }
72
- unless @uttk_unit_options.empty?
73
- opts = @uttk_unit_options
74
- opts = [opts] unless opts.respond_to? :each
75
- opts.each { |x| @command += "#{x} " }
68
+ @command << '--no-verbose'
76
69
  end
77
- @command += '-- %i -- --runner yaml -- %a'
78
- @quiet_print = true
79
- super
70
+ @load_path.each { |x| @command << '-I' << x }
71
+ @requires.to_ocmd_args.each { |x| @command << '-r' << x }
72
+ @command += @uttk_unit_options.to_ocmd_args
73
+ @command << '--' << @input << '--' << '--runner' << 'yaml'
74
+ @command.dir = @dir
80
75
  end
76
+ protected :prologue
77
+
78
+ def run_impl
79
+ @data = @command.run @runner
80
+ end
81
+ protected :run_impl
81
82
 
82
- protected
83
83
  def assertion
84
- result = nil
85
- if @error.my.zero? #FIXME: Shouldn't need to use my here !!
86
- if @output.my.zero?
87
- skip('No result has been collected probably because no test ' +
88
- 'suite has been run')
89
- else
90
- result = YAML.load(@output.my.read)
91
- r = OpenStruct.new(result)
92
- @log[:result] = result
93
- if r.tests_number == 0
94
- skip PassStatus.new.weight, 'No test suite in this file'
95
- end
96
- if r.failures_number != 0 or r.errors_number != 0
97
- rpath = '/^failures$/^default_test/No tests were specified'
98
- if r.failures_number == 1 and result.rpath_find :first, rpath
99
- skip 'No tests were specified'
100
- elsif r.failures_number.zero?
101
- fail 'There are errors'
102
- elsif r.errors_number.zero?
103
- fail 'There are failures'
104
- else
105
- fail 'There are failures and errors'
106
- end
107
- end
108
- pass
109
- end
110
- else
111
- @error.my.open { |io| result = io.read }
112
- raise "Some error occures while running the unit test:\n" + result
84
+ matcher_result = command_matcher[UM::StreamMatcher, {:error => ''}, @data]
85
+ @log << matcher_result
86
+ raise_error('Error output not empty') if matcher_result.failure?
87
+
88
+ if @data.output.zero?
89
+ skip('No result has been collected probably because no test ' +
90
+ 'suite has been run')
91
+ end
92
+
93
+ output = YAML.load @data.output.read
94
+ @log[:result] = output
95
+ o = OpenStruct.new output
96
+
97
+ if o.tests_number.zero?
98
+ skip_pass 'No test suite in this file'
99
+ end
100
+
101
+ pass if o.failures_number.zero? and o.errors_number.zero?
102
+
103
+ rpath = '/^failures$/^default_test/No tests were specified'
104
+ if o.failures_number == 1 and output.rpath_find :first, rpath
105
+ skip 'No tests were specified'
106
+ elsif o.failures_number.zero?
107
+ fail 'There are errors'
108
+ elsif o.errors_number.zero?
109
+ fail 'There are failures'
113
110
  end
111
+
112
+ fail 'There are failures and errors'
113
+ end
114
+ protected :assertion
115
+
116
+ def abort_hook
117
+ @runner.abort @data if @runner and defined? @data
118
+ super
114
119
  end
120
+ protected :abort_hook
115
121
 
122
+ def epilogue
123
+ @data.clean if defined? @data
124
+ super
125
+ end
126
+ protected :epilogue
127
+
128
+ attribute :input, 'the input ruby unit test file',
129
+ nil, :invisible
130
+ attribute :dir, 'the directory where to launch the command',
131
+ [String, Pathname]
116
132
  attribute :load_path, 'directories to add to the $LOAD_PATH variable',
117
133
  :invisible do [] end
118
134
  attribute :requires, 'features to require before load the input',
@@ -128,5 +144,3 @@ module Uttk
128
144
 
129
145
  end # module Uttk
130
146
 
131
-
132
-
@@ -1,7 +1,7 @@
1
1
  # Author:: Vincent CUISSARD <cuissa_v@epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /fey/uttk/trunk/lib/uttk/strategies/SignalCmd.rb 8789 2005-09-27T14:49:49.088376Z ertai $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/SignalCmd.rb 8789 2005-09-27T14:49:49.088376Z ertai $
5
5
 
6
6
 
7
7
  module Uttk
@@ -1,7 +1,7 @@
1
1
  # Author:: Nicolas Despres <nicolas.despres@gmail.com>.
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /fey/uttk/trunk/lib/uttk/strategies/Sleep.rb 8789 2005-09-27T14:49:49.088376Z ertai $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/Sleep.rb 8789 2005-09-27T14:49:49.088376Z ertai $
5
5
 
6
6
 
7
7
  module Uttk
@@ -1,7 +1,7 @@
1
1
  # Author:: Vincent Cuissard <cuissa_v@epita.fr>
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /fey/uttk/trunk/lib/uttk/strategies/SqlQuery.rb 8789 2005-09-27T14:49:49.088376Z ertai $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/SqlQuery.rb 8789 2005-09-27T14:49:49.088376Z ertai $
5
5
 
6
6
 
7
7
  module Uttk
@@ -1,7 +1,7 @@
1
1
  # Author:: The Uttk Team.
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/Strategy.rb 22184 2006-02-23T16:12:25.225774Z pouillar $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/Strategy.rb 24392 2006-07-10T07:36:43.181560Z ertai $
5
5
 
6
6
 
7
7
  require 'set'
@@ -463,6 +463,152 @@ module Uttk
463
463
  protected :check_post_assertion
464
464
 
465
465
 
466
+ # FIXME move them to separate files
467
+ def mk_system_runner env={}
468
+ hooker = StrategyHooker.new @symtbl, @log, env
469
+ OCmd::Runners::System.new.hooker_subscribe hooker
470
+ end
471
+
472
+ class StrategyHooker
473
+ include Hooker
474
+
475
+ attr_reader :env, :symtbl, :log
476
+
477
+ def initialize symtbl, log, env={}
478
+ @env, @symtbl, @log = env, symtbl, log
479
+ end
480
+
481
+ def display_command cmd
482
+ cmd.do_symtbl_gsub! @symtbl
483
+ @log[:running] = cmd.to_sh
484
+ end
485
+
486
+ def before_exec cmd, data
487
+ env_sub = proc do |k,v|
488
+ ENV[k.to_s] = v.do_symtbl_gsub(@symtbl).gsub(/\$(\w+)/) { ENV[$1] }
489
+ end
490
+ @env.each(&env_sub)
491
+ @symtbl[:env].each(&env_sub) if @symtbl[:env]
492
+ end
493
+
494
+ def exception_raised_during_exec
495
+ @data.status = 127
496
+ fail 'exception raised during exec'
497
+ end
498
+
499
+ def already_killed data
500
+ @log.already_killed = data.pid
501
+ end
502
+
503
+ end # class StrategyHooker
504
+
505
+
506
+ class CommandMatcher < UM::UnifiedMatcher
507
+ make Concrete
508
+ cattr_accessor :stream_matcher
509
+
510
+ rule :to_ocmd
511
+
512
+ final(Hash, OCmd::Datas::Data) do |ref, my|
513
+ raise ArgumentError, 'ref is empty' if ref.empty?
514
+ result = UM::MatcherResults.new
515
+ for k,v in ref do
516
+ result << stream_matcher[v, my.send(k), k]
517
+ end
518
+ result
519
+ end
520
+
521
+ final(OCmd::Datas::Data, OCmd::Datas::Data) do |ref, my|
522
+ result = UM::MatcherResults.new
523
+ result << stream_matcher[ref.status, my.status, 'status']
524
+ result << stream_matcher[ref.output, my.output, 'output']
525
+ result << stream_matcher[ref.error, my.error, 'error']
526
+ result
527
+ end
528
+
529
+ def [] matcher, ref, my, name=nil
530
+ matcher = matcher.new if matcher.is_a? Class
531
+ self.stream_matcher = matcher
532
+ super(ref, my, name)
533
+ end
534
+
535
+ end
536
+
537
+ ::UM::StreamMatcher.class_eval do
538
+ final(NilClass, Object, :message => '') { |ref, my| [ true, nil ] }
539
+ end
540
+
541
+ ::UM::GnuDiffMatcher.runner = OCmd::Runners::System.new
542
+
543
+ ::UM::MatcherResults.class_eval do
544
+ def to_uttk_log log
545
+ each do |r|
546
+ log << r
547
+ end
548
+ end
549
+ end
550
+
551
+ ::UM::MatcherResult.class_eval do
552
+ if true
553
+ def to_uttk_log log
554
+ raise ArgumentError, "no name for this matcher result" if @name.nil?
555
+ log.new_node @name do
556
+ log.reason = message unless message.empty?
557
+ if data.nil? or data.is_a? MatchData
558
+ log.my = my.to_s_for_uttk_log unless my.nil?
559
+ log.ref = ref.to_s_for_uttk_log unless ref.nil?
560
+ else
561
+ log.diff = data.output.read
562
+ end
563
+ end
564
+ end
565
+ else
566
+ def to_uttk_log log
567
+ raise ArgumentError, "no name for this matcher result" if @name.nil?
568
+ log["#{@name}_reason"] = message unless message.empty?
569
+ if data.nil? or data.is_a? MatchData
570
+ log["my_#@name"] = my.to_s_for_uttk_log unless my.nil?
571
+ log["ref_#@name"] = ref.to_s_for_uttk_log unless ref.nil?
572
+ else
573
+ log["#{@name}_diff"] = data.output.read
574
+ end
575
+ end
576
+ end
577
+ end
578
+
579
+ ::OCmd::Commands::Command.class_eval do
580
+ def symtbl_gsub! symtbl
581
+ res = @command.symtbl_gsub!(symtbl)
582
+ res = @args.symtbl_gsub!(symtbl) || res
583
+ res = @dir.symtbl_gsub!(symtbl) || res
584
+ (res)? self : nil
585
+ end
586
+ def symtbl_gsub symtbl
587
+ command = @command.symtbl_gsub symtbl
588
+ args = @args.symtbl_gsub symtbl
589
+ dir = @dir.symtbl_gsub symtbl
590
+ if command || args || dir
591
+ self.class.new(command || @command, args || @args, dir || @dir)
592
+ else
593
+ nil
594
+ end
595
+ end
596
+ end
597
+
598
+ cattr_accessor :command_matcher
599
+ self.command_matcher ||= CommandMatcher.new
600
+
601
+ # Examples:
602
+ # assert_cmd @matcher, @data, :output => /foo*/, :error => '', :exit => 0
603
+ # assert_cmd UM::StreamMatcher, @data, :output => 'foo.txt'.to_path
604
+ # The given matcher is used to match command data contents.
605
+ def assert_cmd matcher, my, ref
606
+ matcher_result = command_matcher[matcher, ref, my]
607
+ @log << matcher_result
608
+ fail if matcher_result.failure?
609
+ return matcher_result
610
+ end
611
+
466
612
  # Display conclusions.
467
613
  # Here you can finish some tasks even when the test fails.
468
614
  # Exceptions are absolutly forbidden in this method.
@@ -500,7 +646,6 @@ module Uttk
500
646
  protected :pass_hook
501
647
 
502
648
 
503
-
504
649
  #
505
650
  # Assertions
506
651
  #
@@ -524,11 +669,16 @@ module Uttk
524
669
  raise_status PassStatus.new
525
670
  end
526
671
 
527
- # Skip the test
672
+ # Skip the test (by default the weight is 0%)
528
673
  def skip ( *args )
529
674
  raise_status_custom SkipStatus, *args
530
675
  end
531
676
 
677
+ # Skip the test: the weight is 100%.
678
+ def skip_pass ( message=nil )
679
+ raise_status SkipStatus.new(PassStatus.new.weight, message)
680
+ end
681
+
532
682
  # Force an Error status
533
683
  def raise_error ( message=nil )
534
684
  @symtbl[:flow] << :error
@@ -1,7 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/SubCmd.rb 22112 2006-02-22T08:30:11.236459Z pouillar $
4
+ # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/SubCmd.rb 24394 2006-07-10T07:38:58.276210Z ertai $
5
5
 
6
6
 
7
7
  module Uttk
@@ -9,66 +9,86 @@ module Uttk
9
9
  module Strategies
10
10
 
11
11
  # I run a sub Uttk or an another program that can behave like it.
12
- class SubCmd < CmdBase
12
+ class SubCmd < Strategy
13
13
  include Concrete
14
14
 
15
15
  def prologue
16
- @command = @symtbl[:uttk]
17
- @dir = @symtbl[:pwd]
18
- @quiet_print = true
19
16
  super
17
+ hooker = StrategyHooker.new @symtbl, @log, @env
18
+ @runner = OCmd::Runners::Popen.new.hooker_subscribe hooker
19
+ @command = @symtbl[:uttk].to_ocmd
20
+ @command.dir = @symtbl[:pwd]
21
+ @command.input = @input
22
+ @command += @args.to_ocmd_args
23
+ @command << '-F' << 'Path' << '--dump-status'
20
24
  end
21
25
  protected :prologue
22
26
 
23
27
 
24
28
  def run_impl
25
- super
26
- raise_error 'no uttk output' unless @output.my.exist?
27
- status = nil
29
+ @data = @command.run @runner
30
+ @run_impl_status = nil
28
31
  root_path = @log.path
29
- @output.my.open do |out|
30
- YAML::each_node(out) do |node|
31
- notification = node.symbol_safe_transform
32
- case notification
33
- when Array
34
- path, leaf = notification
35
- @log.update(:new_leaf, root_path + path, leaf)
36
- when Status
37
- status = notification
38
- else
39
- raise_error 'bad sub commad output' if stream.nil?
40
- end
32
+ YAML.load_from_io @data.output do |notification|
33
+ case notification
34
+ when Array
35
+ path, leaf = notification
36
+ @log.update(:new_leaf, root_path + path, leaf)
37
+ when Status
38
+ @run_impl_status = notification
39
+ else
40
+ raise_error 'bad sub commad output'
41
41
  end
42
42
  end
43
- raise_error 'bad status output' unless status.is_a? Status
44
- raise_error 'uttk stderr not empty' unless @error.my.zero?
45
- @status = status
46
- raise_status @status
43
+ @data.waitpid
47
44
  end
48
45
  protected :run_impl
49
46
 
50
47
 
51
48
  def assertion
52
- raise_error "bad exit status #@my_exit" unless [0, 2].include? @my_exit
53
- super
49
+ @data_error_contents = @data.error.read
50
+ ref = { :exit => (/^[02]$/) }
51
+ matcher_result = command_matcher[UM::StreamMatcher, ref, @data]
52
+ raise_error 'bad exit status' if matcher_result.failure?
53
+ raise_error 'bad status output' unless @run_impl_status.is_a? Status
54
+ raise_error 'uttk stderr not empty' unless @data_error_contents.empty?
55
+ @status = @run_impl_status
56
+ raise_status @status
54
57
  end
55
58
  protected :assertion
56
59
 
57
60
 
61
+ def abort_hook
62
+ @runner.abort @data if @runner and defined? @data
63
+ super
64
+ end
65
+ protected :abort_hook
66
+
67
+
58
68
  def error_hook
59
- @log.my_stdout = @output.my.read if @output and @output.my.exist?
60
- @log.my_stderr = @error.my.read if @error and @error.my.exist?
69
+ if defined? @data
70
+ @log.my_stdout = @data.output.to_s_for_uttk_log unless @data.output.nil?
71
+ if defined? @data_error_contents and not @data_error_contents.empty?
72
+ @log.my_stderr = @data_error_contents.to_s_for_uttk_log
73
+ end
74
+ @log.my_exit = @data.status.exitstatus unless @data.status.nil?
75
+ end
61
76
  super
62
77
  end
63
78
  protected :error_hook
64
79
 
65
80
 
66
- def mk_command
67
- @args = "#@args -F Path --dump-status"
81
+ def epilogue
82
+ @data.clean if defined? @data
68
83
  super
69
84
  end
70
- protected :mk_command
85
+ protected :epilogue
86
+
71
87
 
88
+ attribute :args, 'the arguments for the command',
89
+ [Array, String, Numeric]
90
+ attribute :input, 'the input reference', :invisible, nil
91
+ attribute :env, 'environment variables', Hash do {} end
72
92
 
73
93
  end # class SubCmd
74
94