File tree Expand file tree Collapse file tree 7 files changed +106
-1
lines changed Expand file tree Collapse file tree 7 files changed +106
-1
lines changed Original file line number Diff line number Diff line change 176176docs /
177177template-bun-executable
178178/.releaserc
179- functional_tests /features /support /__pycache__ / pexpect_wrapper.cpython-311.pyc
179+ functional_tests /features /support /__pycache__
180180example-host-application
181+ functional_tests /.venv
Original file line number Diff line number Diff line change 1+ ## Executable Functional Tests
2+
3+ #### Setup
4+
5+ Ensure the executable is built:
6+
7+ bun build ../index.ts --compile --outfile /tmp/example-host-application
8+
9+ Install requirements:
10+
11+ pip3 install -r pip-requirements.txt
12+
13+ #### Testing
14+
15+ Run the functional tests:
16+
17+ export EXECUTABLE=/tmp/example-host-application
18+ behave
19+
20+ To run with logging output from the test steps (this is the best set of
21+ arguments I can find):
22+
23+ behave --no-logcapture --no-color --logging-level=DEBUG
Original file line number Diff line number Diff line change 1+ import os
2+
3+ from support .pexpect_wrapper import PExpectWrapper
4+
5+
6+ def before_all (context ):
7+
8+ context .config .setup_logging ()
9+ context .pexpect_wrapper = PExpectWrapper (os .environ .get ('EXECUTABLE' ))
Original file line number Diff line number Diff line change 1+ Feature : Executable
2+
3+ Scenario : Executable success
4+ When the executable is launched
5+ Then the executable should complete successfully
6+ And the executable should have output "INFO Invoking extension"
7+ And the executable should have output "INFO hello world"
Original file line number Diff line number Diff line change 1+ from behave import when , then
2+
3+
4+ @when ('the executable is launched' )
5+ def step_impl (context ):
6+ context .pexpect_wrapper .start ()
7+
8+
9+ @then ('the executable should complete successfully' )
10+ def step_impl (context ):
11+ context .pexpect_wrapper .expect_eof ()
12+ status = context .pexpect_wrapper .complete ()
13+ assert status == 0 , 'unexpected exit status: {}' .format (status )
14+
15+
16+ @then ('the executable should have output "{message}"' )
17+ def step_impl (context , message ):
18+ context .pexpect_wrapper .expect (message )
Original file line number Diff line number Diff line change 1+ from pexpect .popen_spawn import PopenSpawn
2+ from pexpect import EOF
3+ import logging
4+ log = logging .getLogger ("pexpect_wrapper" )
5+
6+
7+ class PExpectWrapper :
8+
9+ def __init__ (self , executable ):
10+ self .executable = executable
11+ self .child = None
12+ self .output = None
13+
14+ def start (self ):
15+ assert self .child is None
16+
17+ self .child = PopenSpawn (self .executable , encoding = 'utf-8' )
18+
19+ def expect (self , message ):
20+ assert self .child is not None
21+
22+ found = ''
23+ while len (self .output ) > 0 :
24+ next_line = self .output .pop (0 )
25+ log .debug ('looking for "{}" in "{}"' .format (message , next_line ))
26+ if message in next_line :
27+ found = next_line
28+ break
29+
30+ assert found != '' , 'expected {} in output' .format (message )
31+
32+
33+ def expect_eof (self ):
34+ assert self .child is not None
35+
36+ self .child .expect (EOF )
37+
38+ def complete (self ):
39+ assert self .child is not None
40+
41+ exit_status = self .child .wait ()
42+
43+ self .output = self .child .before .split ('\n ' )
44+
45+ return exit_status
Original file line number Diff line number Diff line change 1+ pexpect
2+ behave
You can’t perform that action at this time.
0 commit comments