@@ -17,11 +17,12 @@ def run(cmd, verbose=False, **kwargs):
1717
1818 if verbose :
1919 for line in p .stdout :
20- line = p . stdout . readline () .strip ()
20+ line = line .strip ()
2121 if line :
2222 print ' [s] %s' % (line ,)
2323 print " [s] Done"
2424 time .sleep (0.1 )
25+ return p .returncode
2526
2627
2728def spawn (cmd , verbose = False , ** kwargs ):
@@ -39,10 +40,11 @@ def wait(p, match, verbose=False):
3940 p .wait ()
4041 r = False
4142 for line in p .stdout :
43+ line = line .strip ()
4244 if re .search (match , line ):
4345 r = True
4446 if verbose :
45- print " [r] %s" % (line . strip () ,)
47+ print " [r] %s" % (line ,)
4648 if verbose :
4749 print " [r] Done"
4850 return r
@@ -52,35 +54,49 @@ def wait(p, match, verbose=False):
5254def gen (prog , arg = "" , ** kwargs ):
5355 Prog = '' .join ([w .capitalize () for w in prog .split ('_' )])
5456 ctx = {
55- 'python' : kwargs .get ('python' , prog ),
56- 'erlang' : kwargs .get ('erlang' , prog ),
57+ 'prog' : prog ,
58+ 'Prog' : Prog ,
59+ 'rubyver' : os .environ .get ('RUBYVER' , '1.8' ),
60+ 'arg' : arg ,
5761 'java' : kwargs .get ('java' , Prog ),
5862 'dotnet' : kwargs .get ('dotnet' , Prog ),
59- 'ruby' : kwargs .get ('ruby' , prog ),
60- 'php' : kwargs .get ('php' , prog ),
61- 'arg' : arg ,
62- 'rubyver' : os .environ .get ('RUBYVER' , '1.8' ),
63- 'python-puka' : kwargs .get ('python-puka' , prog ),
6463 }
6564 return [
66- ('python' , './venv/bin/python %(python )s.py %(arg)s' % ctx ),
67- ('erlang' , './%(python )s.erl %(arg)s' % ctx ),
65+ ('python' , './venv/bin/python %(prog )s.py %(arg)s' % ctx ),
66+ ('erlang' , './%(prog )s.erl %(arg)s' % ctx ),
6867 ('java' , 'java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:'
6968 'rabbitmq-client.jar %(java)s %(arg)s' % ctx ),
7069 ('dotnet' , 'env MONO_PATH=lib/bin mono %(dotnet)s.exe %(arg)s' % ctx ),
7170 ('ruby' , 'env RUBYOPT=-rubygems GEM_HOME=gems/gems RUBYLIB=gems/lib '
72- 'ruby%(rubyver)s %(ruby )s.rb %(arg)s' % ctx ),
73- ('php' , 'php %(php )s.php %(arg)s' % ctx ),
74- ('python-puka' , './venv/bin/python %(python-puka )s.py %(arg)s' % ctx ),
71+ 'ruby%(rubyver)s %(prog )s.rb %(arg)s' % ctx ),
72+ ('php' , 'php %(prog )s.php %(arg)s' % ctx ),
73+ ('python-puka' , './venv/bin/python %(prog )s.py %(arg)s' % ctx ),
7574 ]
7675
76+ def skip (cwd_cmd , to_skip ):
77+ return [(cwd ,cmd ) for cwd , cmd in cwd_cmd if cwd not in to_skip ]
78+
7779tests = {
7880 'tut1' : (gen ('send' ), gen ('receive' , java = 'Recv' ), 'Hello World!' ),
7981 'tut2' : (gen ('new_task' , arg = '%(arg)s' ), gen ('worker' ), '%(arg)s' ),
8082 'tut3' : (gen ('emit_log' , arg = '%(arg)s' ), gen ('receive_logs' ), '%(arg)s' ),
83+ 'tut4' : (skip (gen ('emit_log_direct' , arg = '%(arg)s %(arg2)s' ),
84+ ['erlang' , 'php' ]),
85+ skip (gen ('receive_logs_direct' , arg = '%(arg)s' ),
86+ ['erlang' , 'php' ]),
87+ '%(arg2)s' ),
88+ 'tut5' : (skip (gen ('emit_log_topic' , arg = '%(arg)s.foo %(arg2)s' ),
89+ ['erlang' , 'php' ]),
90+ skip (gen ('receive_logs_topic' , arg = '%(arg)s.*' ),
91+ ['erlang' , 'php' ]),
92+ '%(arg2)s' ),
93+ 'tut6' : (skip (gen ('rpc_client' , java = 'RPCClient' , dotnet = 'RPCClient' ),
94+ ['erlang' , 'php' ]),
95+ skip (gen ('rpc_server' , java = 'RPCServer' , dotnet = 'RPCServer' ),
96+ ['erlang' , 'php' ]),
97+ 'fib[(]30[)]' ),
8198 }
8299
83-
84100verbose = len (sys .argv ) > 1
85101errors = 0
86102
@@ -89,22 +105,22 @@ def gen(prog, arg="", **kwargs):
89105 for scwd , send_cmd in send_progs :
90106 for rcwd , recv_cmd in recv_progs :
91107 ctx = {
92- 'arg' : 'rand_%s' % (random .randint (1 ,100 ),)
108+ 'arg' : 'rand_%s' % (random .randint (1 ,100 ),),
109+ 'arg2' : 'rand_%s' % (random .randint (1 ,100 ),),
93110 }
94111 rcmd = recv_cmd % ctx
95112 scmd = send_cmd % ctx
96113 mask = output_mask % ctx
97114 p = spawn (rcmd , verbose = verbose , cwd = rcwd )
98- run (scmd , verbose = verbose , cwd = scwd )
99- if wait (p , mask , verbose = verbose ):
100- print " [+] %s %-20s ok" % (test , scwd + '/' + rcwd )
115+ e = run (scmd , verbose = verbose , cwd = scwd )
116+ if wait (p , mask , verbose = verbose ) and e == 0 :
117+ print " [+] %s %-30s ok" % (test , scwd + '/' + rcwd )
101118 else :
102- print " [!] %s %-20s FAILED %r %r" % \
103- (test , scwd + '/' + rcwd , rcmd , scmd )
119+ print " [!] %s %-30s FAILED %r %r (error=%r) " % \
120+ (test , scwd + '/' + rcwd , rcmd , scmd , e )
104121 errors += 1
105122
106123if errors :
107124 print " [!] %s tests failed" % (errors ,)
108125
109126sys .exit (errors )
110-
0 commit comments