root/trunk/tests/test_processes.rb

Revision 668, 1.6 kB (checked in by blackhedd, 1 year ago)

migrated version_0 to trunk

  • Property svn:keywords set to Id
Line 
1 # $Id$
2 #
3 # Author:: Francis Cianfrocca (gmail: blackhedd)
4 # Homepage::  http://rubyeventmachine.com
5 # Date:: 8 April 2006
6 #
7 # See EventMachine and EventMachine::Connection for documentation and
8 # usage examples.
9 #
10 #----------------------------------------------------------------------------
11 #
12 # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13 # Gmail: blackhedd
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of either: 1) the GNU General Public License
17 # as published by the Free Software Foundation; either version 2 of the
18 # License, or (at your option) any later version; or 2) Ruby's License.
19 #
20 # See the file COPYING for complete licensing information.
21 #
22 #---------------------------------------------------------------------------
23 #
24 #
25 #
26
27 $:.unshift "../lib"
28 require 'eventmachine'
29 require 'test/unit'
30
31 class TestProcesses < Test::Unit::TestCase
32
33         # EM::DeferrableChildProcess is a sugaring of a common use-case
34         # involving EM::popen.
35         # Call the #open method on EM::DeferrableChildProcess, passing
36         # a command-string. #open immediately returns an EM::Deferrable
37         # object. It also schedules the forking of a child process, which
38         # will execute the command passed to #open.
39         # When the forked child terminates, the Deferrable will be signalled
40         # and execute its callbacks, passing the data that the child process
41         # wrote to stdout.
42         #
43         def test_deferrable_child_process
44                 ls = ""
45                 EM.run {
46                         d = EM::DeferrableChildProcess.open( "ls -ltr" )
47                         d.callback {|data_from_child|
48                                 ls = data_from_child
49                                 EM.stop
50                         }
51                 }
52                 assert( ls.length > 0)
53         end
54
55 end
56
Note: See TracBrowser for help on using the browser.