ProcessPilot 1.0.0.20120124 → 2.0.0.20120301

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS CHANGED
@@ -1 +1,5 @@
1
- = Muriel Salvan (murielsalvan@users.sourceforge.net)
1
+ = Muriel Salvan (muriel@x-aeon.com)
2
+
3
+ * 0.0.1.20120118
4
+ * 1.0.0.20120124
5
+ * 2.0.0.20120301
data/ChangeLog CHANGED
@@ -1,5 +1,17 @@
1
1
  = Process Pilot Release History
2
2
 
3
+ == 2.0.0.20120301 (Beta)
4
+
5
+ * Updated Release file to last version of RubyPackager (1.1.0)
6
+ * Removed rdoc warning in documentation
7
+ * Updated Copyright information
8
+ * Updated email address of Muriel Salvan
9
+ * Adapted comments to match a better RDoc syntax
10
+ * Renamed public methods to match standard Ruby's conventions
11
+ * Added exit_status to the waiting thread attributes
12
+ * Added IO.read and IO.gets helpers with timeout protection mechanism
13
+ * Bug correction: Set the correct $0 variable in Ruby programs launched with forced sync
14
+
3
15
  == 1.0.0.20120124 (Beta)
4
16
 
5
17
  * Removed dependency on ChildProcess: now uses Open3
data/LICENSE CHANGED
@@ -6,7 +6,7 @@ This list is found in the file named AUTHORS.
6
6
  The AUTHORS and LICENSE files have to be included in any release of software
7
7
  embedding source code of this package, or using it as a derivative software.
8
8
 
9
- Copyright (c) 2010 - 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
9
+ Copyright (c) 2010 - 2012 Muriel Salvan (muriel@x-aeon.com)
10
10
 
11
11
  Redistribution and use in source and binary forms, with or without
12
12
  modification, are permitted provided that the following conditions are met:
data/README CHANGED
@@ -1,6 +1,3 @@
1
- -- This file is best viewed when processed by rdoc.
2
- ++
3
-
4
1
  = Process Pilot
5
2
 
6
3
  Ruby library to pilot interactive command line processes in real time.
@@ -2,7 +2,7 @@
2
2
  # This file has been generated by RubyPackager during a delivery.
3
3
  # More info about RubyPackager: http://rubypackager.sourceforge.net
4
4
  {
5
- :Version => '1.0.0.20120124',
6
- :Tags => [ 'Beta' ],
7
- :DevStatus => 'Beta'
5
+ :version => '2.0.0.20120301',
6
+ :tags => [ 'Beta' ],
7
+ :dev_status => 'Beta'
8
8
  }
@@ -0,0 +1,85 @@
1
+ #--
2
+ # Copyright (c) 2012 Muriel Salvan (muriel@x-aeon.com)
3
+ # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
+ #++
5
+
6
+ # Define some helpers that can be handy in case of process piloting from IO
7
+ class IO
8
+
9
+ alias :gets_ORG_ProcessPilot :gets
10
+ # Add the possibility to gets to take an optional Hash:
11
+ # *:time_out_secs* (_Integer_): Timeout in seconds to read data. nil means no timeout (regular gets) [optional = nil].
12
+ def gets(*iArgs)
13
+ if (iArgs[-1].is_a?(Hash))
14
+ lOptions = iArgs[-1]
15
+ return protect_with_timeout(lOptions[:time_out_secs]) do
16
+ next gets_ORG_ProcessPilot(*iArgs[0..-2])
17
+ end
18
+ else
19
+ return gets_ORG_ProcessPilot(*iArgs)
20
+ end
21
+ end
22
+
23
+ alias :read_ORG_ProcessPilot :read
24
+ # Add the possibility to gets to take an optional Hash:
25
+ # *:time_out_secs* (_Integer_): Timeout in seconds to read data. nil means no timeout (regular gets) [optional = nil].
26
+ def read(*iArgs)
27
+ if (iArgs[-1].is_a?(Hash))
28
+ lOptions = iArgs[-1]
29
+ return protect_with_timeout(lOptions[:time_out_secs]) do
30
+ next read_ORG_ProcessPilot(*iArgs[0..-2])
31
+ end
32
+ else
33
+ return read_ORG_ProcessPilot(*iArgs)
34
+ end
35
+ end
36
+
37
+ # Read lines until a given pattern is recognized
38
+ #
39
+ # Parameters::
40
+ # * *iPattern* (_Regexp_): The pattern to match. Can also be a _String_ for exact match (don't forget \n).
41
+ # * *iOptions* (<em>map<Symbol,Object></em>): Additional options [optional = {}]:
42
+ # * *:time_out_secs* (_Integer_): Timeout in seconds to read data and find the pattern. nil means no timeout. [optional = nil]
43
+ # Return::
44
+ # * <em>list<String></em>: The list of lines read
45
+ def gets_until(iPattern, iOptions = {})
46
+ rLstLines = []
47
+
48
+ lTimeOutSecs = iOptions[:time_out_secs]
49
+ protect_with_timeout(lTimeOutSecs) do
50
+ if (iPattern.is_a?(Regexp))
51
+ while ((rLstLines << self.gets(:time_out_secs => lTimeOutSecs))[-1].match(iPattern) == nil)
52
+ #$stdout.puts "Read from IO: #{rLstLines[-1].inspect}"
53
+ raise(IOError, 'End of stream') if (rLstLines[-1] == nil)
54
+ end
55
+ else
56
+ while ((rLstLines << self.gets(:time_out_secs => lTimeOutSecs))[-1] != iPattern)
57
+ #$stdout.puts "Read from IO: #{rLstLines[-1].inspect}"
58
+ raise(IOError, 'End of stream') if (rLstLines[-1] == nil)
59
+ end
60
+ end
61
+ #$stdout.puts "Read from IO: #{rLstLines[-1].inspect}"
62
+ end
63
+
64
+ return rLstLines
65
+ end
66
+
67
+ private
68
+
69
+ # Protect some code with an optional timeout.
70
+ # Return the value of the client code block.
71
+ #
72
+ # Parameters::
73
+ # * *iTimeOutSecs* (_Integer_): Time out to perform. Can be nil for no timeout.
74
+ # * _CodeBlock_: The code called
75
+ def protect_with_timeout(iTimeOutSecs)
76
+ if (iTimeOutSecs == nil)
77
+ return yield
78
+ else
79
+ return Timeout::timeout(iTimeOutSecs) do
80
+ next yield
81
+ end
82
+ end
83
+ end
84
+
85
+ end
@@ -1,10 +1,11 @@
1
1
  #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
2
+ # Copyright (c) 2012 Muriel Salvan (muriel@x-aeon.com)
3
3
  # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
4
  #++
5
5
 
6
6
  require 'open3'
7
7
  require 'timeout'
8
+ require 'processpilot/io'
8
9
 
9
10
  module ProcessPilot
10
11
 
@@ -12,20 +13,28 @@ module ProcessPilot
12
13
 
13
14
  # Constructor
14
15
  #
15
- # Parameters:
16
- # * *iWaitThread* (_Thread_): The waiting thread, can be nil if already stopped or dead
16
+ # Parameters::
17
+ # * *iWaitThread* (_Thread_): The waiting thread, can be nil
17
18
  def initialize(iWaitThread)
18
19
  @WaitThread = iWaitThread
19
20
  end
20
21
 
21
22
  # Has the waiting process exited already ?
22
23
  #
23
- # Return:
24
+ # Return::
24
25
  # * _Boolean_: Has the waiting process exited already ?
25
26
  def exited?
26
27
  return ((@WaitThread == nil) or (@WaitThread.stop?))
27
28
  end
28
29
 
30
+ # Return the exit status
31
+ #
32
+ # Return::
33
+ # * <em>Process::Status</em>: The exit status
34
+ def exit_status
35
+ return (@WaitThread == nil) ? nil : @WaitThread.value
36
+ end
37
+
29
38
  # Stop the process' execution
30
39
  def stop
31
40
  @WaitThread.kill if @WaitThread
@@ -35,83 +44,39 @@ module ProcessPilot
35
44
 
36
45
  # Pilot a process.
37
46
  # This will create a new thread for the process to be run.
38
- # If the process is a Ruby process, you can force STDOUT sync by specifying it in options. In this case the command line should begin with the Ruby file name to be executed (don't use ruby executable, and specifiy ruby options in iOptions[:RubyCmdLine]).
47
+ # If the process is a Ruby process, you can force STDOUT sync by specifying it in options. In this case the command line should begin with the Ruby file name to be executed (don't use ruby executable, and specifiy ruby options in iOptions[:ruby_cmd_line]).
39
48
  #
40
- # Parameters:
49
+ # Parameters::
41
50
  # * *iCmdLine* (<em>list<String></em>): The process' command line
42
51
  # * *iOptions* (<em>map<Symbol,Object></em>): Optional arguments [optional = nil]:
43
- # ** *:ForceRubyProcessSync* (_Boolean_): If the command line is a Ruby process, force setting STDOUT to be synced. [optional = false]
44
- # ** *:RubyCmdLine* (<em>list<String></em>): Command line of Ruby interpreter with options (used only if :ForceRubyProcessSync is true) [optional = ['ruby']]
45
- # ** *:Debug* (_Boolean_): Do we activate some debugging traces ? (need rUtilAnts gem if activated) [optional = false]
52
+ # * *:force_ruby_process_sync* (_Boolean_): If the command line is a Ruby process, force setting STDOUT to be synced. [optional = false]
53
+ # * *:ruby_cmd_line* (<em>list<String></em>): Command line of Ruby interpreter with options (used only if :force_ruby_process_sync is true) [optional = ['ruby']]
54
+ # * *:debug* (_Boolean_): Do we activate some debugging traces ? (need rUtilAnts gem if activated) [optional = false]
46
55
  # * _CodeBlock_: The code called for process piloting:
47
- # ** Parameters:
48
- # ** *oStdIN* (_IO_): The process' STDIN
49
- # ** *iStdOUT* (_IO_): The process' STDOUT
50
- # ** *iStdERR* (_IO_): The process' STDERR
51
- # ** *iChildProcess* (_ChildProcess_): The corresponding child process. Don't use it to pilot std* IO objects. Depending on the platforms, this might be nil.
56
+ # * Parameters::
57
+ # * *oStdIN* (_IO_): The process' STDIN
58
+ # * *iStdOUT* (_IO_): The process' STDOUT
59
+ # * *iStdERR* (_IO_): The process' STDERR
60
+ # * *iChildProcess* (_ChildProcess_): The corresponding child process. Don't use it to pilot std* IO objects. Depending on the platforms, this might be nil (always nil for Ruby < 1.9).
52
61
  def self.pilot(*iArgs)
53
62
  iCmdLine = iArgs
54
63
  iOptions = (iArgs[-1].is_a?(Hash)) ? iArgs.pop : {}
55
- iForceRubyProcessSync = (iOptions[:ForceRubyProcessSync] || false)
56
- iRubyCmdLine = (iOptions[:RubyCmdLine] || ['ruby'])
57
- iDebug = (iOptions[:Debug] || false)
64
+ iForceRubyProcessSync = (iOptions[:force_ruby_process_sync] || false)
65
+ iRubyCmdLine = (iOptions[:ruby_cmd_line] || ['ruby'])
66
+ iDebug = (iOptions[:debug] || false)
58
67
 
59
68
  if ((iDebug) and (require 'rUtilAnts/Logging'))
60
69
  # First time it was required: set it up
61
- RUtilAnts::Logging::initializeLogging('', '')
62
- activateLogDebug(true)
70
+ RUtilAnts::Logging::install_logger_on_object(:debug_mode => true)
63
71
  end
64
72
 
65
73
  # Wrap eventually Ruby command line
66
74
  lRealCmdLine = (iForceRubyProcessSync) ? iRubyCmdLine + [ "#{File.dirname(__FILE__)}/wrapper.rb" ] + iCmdLine : iCmdLine
67
75
 
68
- logDebug "[ProcessPilot] Command line: #{lRealCmdLine.inspect}" if iDebug
76
+ log_debug "[ProcessPilot] Command line: #{lRealCmdLine.inspect}" if iDebug
69
77
  Open3::popen3(*lRealCmdLine) do |oStdIN, iStdOUT, iStdERR, iWaitThread|
70
78
  yield(oStdIN, iStdOUT, iStdERR, ChildProcessInfo.new(iWaitThread))
71
79
  end
72
80
  end
73
81
 
74
82
  end
75
-
76
- # Define some helpers that can be handy in case of process piloting from IO
77
- class IO
78
-
79
- alias :gets_ORG_ProcessPilot :gets
80
- # Add the possibility to gets to take an optional Hash:
81
- # *:TimeOutSecs* (_Integer_): Timeout in seconds to read data. nil means no timeout (regular gets) [optional = nil].
82
- def gets(*iArgs)
83
- if (iArgs[-1].is_a?(Hash))
84
- lOptions = iArgs[-1]
85
- lTimeOutSecs = lOptions[:TimeOutSecs]
86
- if (lTimeOutSecs == nil)
87
- return gets_ORG_ProcessPilot(*iArgs[0..-2])
88
- else
89
- return Timeout::timeout(lTimeOutSecs) do
90
- next gets_ORG_ProcessPilot(*iArgs[0..-2])
91
- end
92
- end
93
- else
94
- return gets_ORG_ProcessPilot(*iArgs)
95
- end
96
- end
97
-
98
- alias :read_ORG_ProcessPilot :read
99
- # Add the possibility to gets to take an optional Hash:
100
- # *:TimeOutSecs* (_Integer_): Timeout in seconds to read data. nil means no timeout (regular gets) [optional = nil].
101
- def read(*iArgs)
102
- if (iArgs[-1].is_a?(Hash))
103
- lOptions = iArgs[-1]
104
- lTimeOutSecs = lOptions[:TimeOutSecs]
105
- if (lTimeOutSecs == nil)
106
- return read_ORG_ProcessPilot(*iArgs[0..-2])
107
- else
108
- return Timeout::timeout(lTimeOutSecs) do
109
- next read_ORG_ProcessPilot(*iArgs[0..-2])
110
- end
111
- end
112
- else
113
- return read_ORG_ProcessPilot(*iArgs)
114
- end
115
- end
116
-
117
- end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
2
+ # Copyright (c) 2012 Muriel Salvan (muriel@x-aeon.com)
3
3
  # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
4
  #++
5
5
 
@@ -10,7 +10,12 @@ $stdout.sync = true
10
10
  iRBFileName = ARGV[0]
11
11
 
12
12
  # Adapt ARGV for this rb file to get its arguments correctly
13
- # TODO: Maybe adapt other variables ...
13
+ # Adapt variables modified by the wrapper
14
+ # ARGV
14
15
  ARGV.replace(ARGV[1..-1])
16
+ # $0
17
+ $__ProcessPilot__RealProgramName = File.expand_path(iRBFileName)
18
+ alias $0 $__ProcessPilot__RealProgramName
15
19
 
20
+ # Execute the normal program
16
21
  load iRBFileName
metadata CHANGED
@@ -3,11 +3,11 @@ name: ProcessPilot
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
6
+ - 2
7
7
  - 0
8
8
  - 0
9
- - 20120124
10
- version: 1.0.0.20120124
9
+ - 20120301
10
+ version: 2.0.0.20120301
11
11
  platform: ruby
12
12
  authors:
13
13
  - Muriel Salvan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-24 00:00:00 +01:00
18
+ date: 2012-03-01 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -27,9 +27,9 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  segments:
30
+ - 1
30
31
  - 0
31
- - 3
32
- version: "0.3"
32
+ version: "1.0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  description: Ruby library giving a simple way to pilot an external process' stdin, stdout and stderr in real time. Very useful for interactive processes testing or automation.
@@ -44,32 +44,12 @@ files:
44
44
  - AUTHORS
45
45
  - ChangeLog
46
46
  - Credits
47
+ - lib/processpilot/io.rb
47
48
  - lib/processpilot/processpilot.rb
48
49
  - lib/processpilot/wrapper.rb
49
50
  - LICENSE
50
51
  - README
51
52
  - ReleaseInfo
52
- - test/ProcessPilotTest/Common.rb
53
- - test/ProcessPilotTest/NonRuby.rb
54
- - test/ProcessPilotTest/Ruby.rb
55
- - test/Programs/Bash/Interactive.sh
56
- - test/Programs/Bash/InteractivePrompt.sh
57
- - test/Programs/Bash/InteractivePromptSTDERR.sh
58
- - test/Programs/Bash/InteractiveSeveralPrompts.sh
59
- - test/Programs/Bash/InteractiveSTDERR.sh
60
- - test/Programs/Bash/NotInteractive.sh
61
- - test/Programs/Bash/NotInteractiveSTDERR.sh
62
- - test/Programs/Ruby/NormalSTDOUT.rb
63
- - test/Programs/Ruby/Scenario.rb
64
- - test/Programs/Ruby/SyncedSTDOUT.rb
65
- - test/Programs/Windows/Interactive.bat
66
- - test/Programs/Windows/InteractivePrompt.bat
67
- - test/Programs/Windows/InteractivePromptSTDERR.bat
68
- - test/Programs/Windows/InteractiveSeveralPrompts.bat
69
- - test/Programs/Windows/InteractiveSTDERR.bat
70
- - test/Programs/Windows/NotInteractive.bat
71
- - test/Programs/Windows/NotInteractiveSTDERR.bat
72
- - test/run.rb
73
53
  has_rdoc: true
74
54
  homepage: http://processpilot.sourceforge.net/
75
55
  licenses: []
@@ -102,5 +82,5 @@ rubygems_version: 1.3.7
102
82
  signing_key:
103
83
  specification_version: 3
104
84
  summary: Ruby library to pilot interactive command line processes in real time.
105
- test_files:
106
- - test/run.rb
85
+ test_files: []
86
+
@@ -1,241 +0,0 @@
1
- #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
3
- # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
- #++
5
-
6
- module ProcessPilotTest
7
-
8
- module Common
9
-
10
- # Get the OS dependant command line for testing non interactive processes
11
- #
12
- # Return:
13
- # * <em>list<String></em>: Command line
14
- def getNotInteractiveCmdLine
15
- rCmdLine = nil
16
-
17
- case $rUtilAnts_Platform_Info.os
18
- when RUtilAnts::Platform::OS_WINDOWS
19
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Windows/NotInteractive.bat"]
20
- when RUtilAnts::Platform::OS_LINUX
21
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/NotInteractive.sh"]
22
- when RUtilAnts::Platform::OS_CYGWIN
23
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/NotInteractive.sh"]
24
- else
25
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/NotInteractive.sh"]
26
- end
27
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
28
-
29
- return rCmdLine
30
- end
31
-
32
- # Get the OS dependant command line for testing non interactive processes on STDERR
33
- #
34
- # Return:
35
- # * <em>list<String></em>: Command line
36
- def getNotInteractiveCmdLineSTDERR
37
- rCmdLine = nil
38
-
39
- case $rUtilAnts_Platform_Info.os
40
- when RUtilAnts::Platform::OS_WINDOWS
41
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Windows/NotInteractiveSTDERR.bat"]
42
- when RUtilAnts::Platform::OS_LINUX
43
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/NotInteractiveSTDERR.sh"]
44
- when RUtilAnts::Platform::OS_CYGWIN
45
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/NotInteractiveSTDERR.sh"]
46
- else
47
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/NotInteractiveSTDERR.sh"]
48
- end
49
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
50
-
51
- return rCmdLine
52
- end
53
-
54
- # Get the OS dependant command line for testing interactive processes
55
- #
56
- # Return:
57
- # * <em>list<String></em>: Command line
58
- def getInteractiveCmdLine
59
- rCmdLine = nil
60
-
61
- case $rUtilAnts_Platform_Info.os
62
- when RUtilAnts::Platform::OS_WINDOWS
63
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Windows/Interactive.bat"]
64
- when RUtilAnts::Platform::OS_LINUX
65
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/Interactive.sh"]
66
- when RUtilAnts::Platform::OS_CYGWIN
67
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/Interactive.sh"]
68
- else
69
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/Interactive.sh"]
70
- end
71
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
72
-
73
- return rCmdLine
74
- end
75
-
76
- # Get the OS dependant command line for testing interactive processes on STDERR
77
- #
78
- # Return:
79
- # * <em>list<String></em>: Command line
80
- def getInteractiveCmdLineSTDERR
81
- rCmdLine = nil
82
-
83
- case $rUtilAnts_Platform_Info.os
84
- when RUtilAnts::Platform::OS_WINDOWS
85
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Windows/InteractiveSTDERR.bat"]
86
- when RUtilAnts::Platform::OS_LINUX
87
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractiveSTDERR.sh"]
88
- when RUtilAnts::Platform::OS_CYGWIN
89
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractiveSTDERR.sh"]
90
- else
91
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractiveSTDERR.sh"]
92
- end
93
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
94
-
95
- return rCmdLine
96
- end
97
-
98
- # Get the OS dependant command line for testing interactive processes with a prompt
99
- #
100
- # Return:
101
- # * <em>list<String></em>: Command line
102
- def getInteractivePromptCmdLine
103
- rCmdLine = nil
104
-
105
- case $rUtilAnts_Platform_Info.os
106
- when RUtilAnts::Platform::OS_WINDOWS
107
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Windows/InteractivePrompt.bat"]
108
- when RUtilAnts::Platform::OS_LINUX
109
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractivePrompt.sh"]
110
- when RUtilAnts::Platform::OS_CYGWIN
111
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractivePrompt.sh"]
112
- else
113
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractivePrompt.sh"]
114
- end
115
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
116
-
117
- return rCmdLine
118
- end
119
-
120
- # Get the OS dependant command line for testing interactive processes with a prompt on STDERR
121
- #
122
- # Return:
123
- # * <em>list<String></em>: Command line
124
- def getInteractivePromptCmdLineSTDERR
125
- rCmdLine = nil
126
-
127
- case $rUtilAnts_Platform_Info.os
128
- when RUtilAnts::Platform::OS_WINDOWS
129
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Windows/InteractivePromptSTDERR.bat"]
130
- when RUtilAnts::Platform::OS_LINUX
131
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractivePromptSTDERR.sh"]
132
- when RUtilAnts::Platform::OS_CYGWIN
133
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractivePromptSTDERR.sh"]
134
- else
135
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractivePromptSTDERR.sh"]
136
- end
137
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
138
-
139
- return rCmdLine
140
- end
141
-
142
- # Get the OS dependant command line for testing interactive processes with several prompts
143
- #
144
- # Return:
145
- # * <em>list<String></em>: Command line
146
- def getInteractiveSeveralPrompts
147
- rCmdLine = nil
148
-
149
- case $rUtilAnts_Platform_Info.os
150
- when RUtilAnts::Platform::OS_WINDOWS
151
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Windows/InteractiveSeveralPrompts.bat"]
152
- when RUtilAnts::Platform::OS_LINUX
153
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractiveSeveralPrompts.sh"]
154
- when RUtilAnts::Platform::OS_CYGWIN
155
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractiveSeveralPrompts.sh"]
156
- else
157
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Bash/InteractiveSeveralPrompts.sh"]
158
- end
159
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
160
-
161
- return rCmdLine
162
- end
163
-
164
- # Get the command line for testing synced Ruby programs
165
- #
166
- # Return:
167
- # * <em>list<String></em>: Command line
168
- def getSyncedRubyCmdLine
169
- rCmdLine = ['ruby', "#{$ProcessPilotTest_RootPath}/test/Programs/Ruby/SyncedSTDOUT.rb"]
170
-
171
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
172
-
173
- return rCmdLine
174
- end
175
-
176
- # Get the command line for testing normal Ruby programs
177
- #
178
- # Return:
179
- # * <em>list<String></em>: Command line
180
- def getNormalRubyCmdLine
181
- rCmdLine = ['ruby', "#{$ProcessPilotTest_RootPath}/test/Programs/Ruby/NormalSTDOUT.rb"]
182
-
183
- rCmdLine << { :Debug => true } if ($ProcessPilotTest_Debug)
184
-
185
- return rCmdLine
186
- end
187
-
188
- # Get the command line for testing normal Ruby programs and forcing them to sync
189
- #
190
- # Return:
191
- # * <em>list<String></em>: Command line
192
- def getNormalRubyWithSyncCmdLine
193
- rCmdLine = ["#{$ProcessPilotTest_RootPath}/test/Programs/Ruby/NormalSTDOUT.rb"]
194
-
195
- lOptions = {
196
- :ForceRubyProcessSync => true
197
- }
198
- lOptions[:Debug] = true if ($ProcessPilotTest_Debug)
199
- rCmdLine << lOptions
200
-
201
- return rCmdLine
202
- end
203
-
204
- # Assert a common given scenario.
205
- # This has been put in such a method as the same scenario is used in different scripts.
206
- #
207
- # Parameters:
208
- # * *oStdIN* (_IO_): STDIN
209
- # * *iStdOUT* (_IO_): STDOUT
210
- # * *iStdERR* (_IO_): STDERR
211
- # * *iChildProcess* (_ChildProcess_): Corresponding ChildProcess
212
- def assert_testing_scenario(oStdIN, iStdOUT, iStdERR, iChildProcess)
213
- assert_equal "STDOUT Line 1.\n", iStdOUT.gets(:TimeOutSecs => 1)
214
- assert_equal 'Enter string 1 from STDOUT: ', iStdOUT.read(28)
215
- assert_raise Timeout::Error do
216
- iStdERR.read(1, :TimeOutSecs => 1)
217
- end
218
- assert_raise Timeout::Error do
219
- iStdOUT.read(1, :TimeOutSecs => 1)
220
- end
221
- oStdIN.write "Test String 1\n"
222
- assert_equal "STDOUT Line 2: Test String 1\n", iStdOUT.gets(:TimeOutSecs => 1)
223
- assert_equal "STDERR Line 1.\n", iStdERR.gets(:TimeOutSecs => 1)
224
- assert_equal 'Enter string 2 from STDERR: ', iStdERR.read(28)
225
- assert_raise Timeout::Error do
226
- iStdERR.read(1, :TimeOutSecs => 1)
227
- end
228
- assert_raise Timeout::Error do
229
- iStdOUT.read(1, :TimeOutSecs => 1)
230
- end
231
- oStdIN.write "Test String 2\n"
232
- assert_equal "STDOUT Line 3: Test String 2\n", iStdOUT.gets(:TimeOutSecs => 1)
233
- assert_equal "STDERR Line 2.\n", iStdERR.gets(:TimeOutSecs => 1)
234
- assert_equal nil, iStdOUT.gets(:TimeOutSecs => 1)
235
- assert_equal nil, iStdERR.gets(:TimeOutSecs => 1)
236
- assert iChildProcess.exited?
237
- end
238
-
239
- end
240
-
241
- end
@@ -1,104 +0,0 @@
1
- #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
3
- # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
- #++
5
-
6
- module ProcessPilotTest
7
-
8
- class NonRuby < ::Test::Unit::TestCase
9
-
10
- include ProcessPilotTest::Common
11
-
12
- def testNotInteractiveSTDOUT
13
- ProcessPilot::pilot(*getNotInteractiveCmdLine) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
14
- assert_equal "Hello World\n", iStdOUT.gets(:TimeOutSecs => 1)
15
- assert_nil iStdERR.gets
16
- assert iChildProcess.exited?
17
- end
18
- end
19
-
20
- def testNotInteractiveSTDOUTEndOfProcess
21
- ProcessPilot::pilot(*getNotInteractiveCmdLine) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
22
- assert_equal "Hello World\n", iStdOUT.gets(:TimeOutSecs => 1)
23
- assert_equal nil, iStdOUT.gets(:TimeOutSecs => 1)
24
- assert_equal nil, iStdERR.gets(:TimeOutSecs => 1)
25
- assert iChildProcess.exited?
26
- end
27
- end
28
-
29
- def testNotInteractiveSTDERR
30
- ProcessPilot::pilot(*getNotInteractiveCmdLineSTDERR) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
31
- assert_equal nil, iStdOUT.gets(:TimeOutSecs => 1)
32
- assert_equal "Hello World\n", iStdERR.gets(:TimeOutSecs => 1)
33
- assert_equal nil, iStdERR.gets(:TimeOutSecs => 1)
34
- assert iChildProcess.exited?
35
- end
36
- end
37
-
38
- def testInteractiveSTDOUT
39
- ProcessPilot::pilot(*getInteractiveCmdLine) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
40
- assert_equal "Hello World\n", iStdOUT.gets(:TimeOutSecs => 1)
41
- assert_raise Timeout::Error do
42
- iStdOUT.gets(:TimeOutSecs => 1)
43
- end
44
- oStdIN.write "Test String\n"
45
- assert_equal "Hello Test String\n", iStdOUT.gets(:TimeOutSecs => 1)
46
- assert_equal nil, iStdOUT.gets(:TimeOutSecs => 1)
47
- assert iChildProcess.exited?
48
- end
49
- end
50
-
51
- def testInteractiveSTDERR
52
- ProcessPilot::pilot(*getInteractiveCmdLineSTDERR) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
53
- assert_raise Timeout::Error do
54
- iStdOUT.gets(:TimeOutSecs => 1)
55
- end
56
- assert_equal "Hello World\n", iStdERR.gets(:TimeOutSecs => 1)
57
- assert_raise Timeout::Error do
58
- iStdERR.gets(:TimeOutSecs => 1)
59
- end
60
- oStdIN.write "Test String\n"
61
- assert_equal nil, iStdOUT.gets(:TimeOutSecs => 1)
62
- assert_equal "Hello Test String\n", iStdERR.gets(:TimeOutSecs => 1)
63
- assert_equal nil, iStdERR.gets(:TimeOutSecs => 1)
64
- assert iChildProcess.exited?
65
- end
66
- end
67
-
68
- def testInteractiveWithPromptSTDOUT
69
- ProcessPilot::pilot(*getInteractivePromptCmdLine) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
70
- assert_equal "Hello World\n", iStdOUT.gets(:TimeOutSecs => 1)
71
- assert_equal 'Enter string: ', iStdOUT.read(14)
72
- assert_raise Timeout::Error do
73
- iStdOUT.gets(:TimeOutSecs => 1)
74
- end
75
- oStdIN.write "Test String\n"
76
- assert_equal "Hello Test String\n", iStdOUT.gets(:TimeOutSecs => 1)
77
- assert_equal nil, iStdOUT.gets(:TimeOutSecs => 1)
78
- assert iChildProcess.exited?
79
- end
80
- end
81
-
82
- def testInteractiveWithPromptSTDERR
83
- ProcessPilot::pilot(*getInteractivePromptCmdLineSTDERR) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
84
- assert_equal "Hello World\n", iStdERR.gets(:TimeOutSecs => 1)
85
- assert_equal 'Enter string: ', iStdERR.read(14)
86
- assert_raise Timeout::Error do
87
- iStdERR.gets(:TimeOutSecs => 1)
88
- end
89
- oStdIN.write "Test String\n"
90
- assert_equal "Hello Test String\n", iStdERR.gets(:TimeOutSecs => 1)
91
- assert_equal nil, iStdERR.gets(:TimeOutSecs => 1)
92
- assert iChildProcess.exited?
93
- end
94
- end
95
-
96
- def testSeveralPrompts
97
- ProcessPilot::pilot(*getInteractiveSeveralPrompts) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
98
- assert_testing_scenario(oStdIN, iStdOUT, iStdERR, iChildProcess)
99
- end
100
- end
101
-
102
- end
103
-
104
- end
@@ -1,35 +0,0 @@
1
- #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
3
- # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
- #++
5
-
6
- module ProcessPilotTest
7
-
8
- class Ruby < ::Test::Unit::TestCase
9
-
10
- include ProcessPilotTest::Common
11
-
12
- def testSyncedSTDOUT
13
- ProcessPilot::pilot(*getSyncedRubyCmdLine) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
14
- assert_testing_scenario(oStdIN, iStdOUT, iStdERR, iChildProcess)
15
- end
16
- end
17
-
18
- def testNormalSTDOUT
19
- ProcessPilot::pilot(*getNormalRubyCmdLine) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
20
- assert_raise Timeout::Error do
21
- iStdOUT.read(1, :TimeOutSecs => 1)
22
- end
23
- iChildProcess.stop
24
- end
25
- end
26
-
27
- def testNormalSTDOUTWithForceSync
28
- ProcessPilot::pilot(*getNormalRubyWithSyncCmdLine) do |oStdIN, iStdOUT, iStdERR, iChildProcess|
29
- assert_testing_scenario(oStdIN, iStdOUT, iStdERR, iChildProcess)
30
- end
31
- end
32
-
33
- end
34
-
35
- end
@@ -1,5 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "Hello World"
4
- read VAR
5
- echo "Hello ${VAR}"
@@ -1,6 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "Hello World"
4
- echo -n "Enter string: "
5
- read VAR
6
- echo "Hello ${VAR}"
@@ -1,6 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "Hello World" >&2
4
- echo -n "Enter string: " >&2
5
- read VAR
6
- echo "Hello ${VAR}" >&2
@@ -1,5 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "Hello World" >&2
4
- read VAR
5
- echo "Hello ${VAR}" >&2
@@ -1,11 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "STDOUT Line 1."
4
- echo -n "Enter string 1 from STDOUT: "
5
- read VAR
6
- echo "STDOUT Line 2: ${VAR}"
7
- echo "STDERR Line 1." >&2
8
- echo -n "Enter string 2 from STDERR: " >&2
9
- read VAR
10
- echo "STDOUT Line 3: ${VAR}"
11
- echo "STDERR Line 2." >&2
@@ -1,3 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "Hello World"
@@ -1,3 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "Hello World" >&2
@@ -1,8 +0,0 @@
1
- #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
3
- # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
- #++
5
-
6
- require "#{File.dirname(__FILE__)}/Scenario.rb"
7
-
8
- ProcessPilotTest::Scenario::run
@@ -1,25 +0,0 @@
1
- #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
3
- # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
- #++
5
-
6
- module ProcessPilotTest
7
-
8
- module Scenario
9
-
10
- # Execute the testing scenario
11
- def self.run
12
- $stdout.puts 'STDOUT Line 1.'
13
- $stdout.write 'Enter string 1 from STDOUT: '
14
- lVar = $stdin.gets
15
- $stdout.puts "STDOUT Line 2: #{lVar}"
16
- $stderr.puts 'STDERR Line 1.'
17
- $stderr.write 'Enter string 2 from STDERR: '
18
- lVar = $stdin.gets
19
- $stdout.puts "STDOUT Line 3: #{lVar}"
20
- $stderr.puts 'STDERR Line 2.'
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,10 +0,0 @@
1
- #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
3
- # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
- #++
5
-
6
- $stdout.sync = true
7
-
8
- require "#{File.dirname(__FILE__)}/Scenario.rb"
9
-
10
- ProcessPilotTest::Scenario::run
@@ -1,4 +0,0 @@
1
- @echo off
2
- echo Hello World
3
- set /p var="" %=%
4
- echo Hello %var%
@@ -1,4 +0,0 @@
1
- @echo off
2
- echo Hello World
3
- set /p var="Enter string: " %=%
4
- echo Hello %var%
@@ -1,5 +0,0 @@
1
- @echo off
2
- echo Hello World>&2
3
- echo/|set /p ="Enter string: " >&2
4
- set /p var= %=%
5
- echo Hello %var%>&2
@@ -1,4 +0,0 @@
1
- @echo off
2
- echo Hello World>&2
3
- set /p var="" %=%
4
- echo Hello %var%>&2
@@ -1,10 +0,0 @@
1
- @echo off
2
- echo STDOUT Line 1.
3
- set /p var="Enter string 1 from STDOUT: " %=%
4
- echo STDOUT Line 2: %var%
5
- set line=
6
- echo STDERR Line 1.>&2
7
- echo/|set /p ="Enter string 2 from STDERR: " >&2
8
- set /p var= %=%
9
- echo STDOUT Line 3: %var%
10
- echo STDERR Line 2.>&2
@@ -1,2 +0,0 @@
1
- @echo off
2
- echo Hello World
@@ -1,2 +0,0 @@
1
- @echo off
2
- echo Hello World>&2
@@ -1,30 +0,0 @@
1
- #--
2
- # Copyright (c) 2012 Muriel Salvan (murielsalvan@users.sourceforge.net)
3
- # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
- #++
5
-
6
- $ProcessPilotTest_Debug = true
7
-
8
- require 'test/unit'
9
- require 'rUtilAnts/Logging'
10
- RUtilAnts::Logging::initializeLogging('', '')
11
- activateLogDebug($ProcessPilotTest_Debug)
12
- require 'rUtilAnts/Misc'
13
- RUtilAnts::Misc::initializeMisc
14
- require 'rUtilAnts/Platform'
15
- RUtilAnts::Platform::initializePlatform
16
-
17
- $ProcessPilotTest_RootPath = File.expand_path("#{File.dirname(__FILE__)}/..")
18
-
19
- # Add the test directory to the current load path
20
- $: << "#{$ProcessPilotTest_RootPath}/test"
21
- # And the lib one too
22
- $: << "#{$ProcessPilotTest_RootPath}/lib"
23
-
24
- # Require the main library
25
- require 'processpilot/processpilot'
26
-
27
- # Load test files to execute
28
- require 'ProcessPilotTest/Common'
29
- require 'ProcessPilotTest/NonRuby'
30
- require 'ProcessPilotTest/Ruby'