Skip to content

Commit 4684a36

Browse files
committed
Add a test
1 parent 35913de commit 4684a36

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/sage/doctest/test.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,18 @@
297297
298298
A different kind of crash::
299299
300-
sage: subprocess.call(["sage", "-t", "--warn-long", "0", # long time
301-
....: "--random-seed=0", "--optional=sage", "fail_and_die.rst"], **kwds)
300+
sage: # long time
301+
sage: proc = subprocess.run(["sage", "-t", "--warn-long", "0",
302+
....: "--random-seed=0", "--optional=sage", "fail_and_die.rst"], **kwds,
303+
....: stdout=subprocess.PIPE, text=True)
304+
sage: # the replacements are needed to avoid the strings being interpreted
305+
....: # specially by the doctesting framework
306+
sage: print(proc.stdout.replace('sage:', 'sage<COLON>').replace('....:', '<DOTSCOLON>'))
302307
Running doctests...
303308
Doctesting 1 file.
304309
sage -t --warn-long 0.0 --random-seed=0 fail_and_die.rst
305310
**********************************************************************
306-
File "fail_and_die.rst", line 5, in sage.doctest.tests.fail_and_die
311+
File "fail_and_die.rst", line 8, in sage.doctest.tests.fail_and_die
307312
Failed example:
308313
this_gives_a_NameError
309314
Exception raised:
@@ -313,11 +318,18 @@
313318
Killed due to kill signal
314319
**********************************************************************
315320
Tests run before process (pid=...) failed:
316-
...
321+
sage<COLON> import time, signal ## line 4 ##
322+
sage<COLON> print(1,
323+
<DOTSCOLON> 2) ## line 5 ##
324+
1 2
325+
sage<COLON> this_gives_a_NameError ## line 8 ##
326+
sage<COLON> os.kill(os.getpid(), signal.SIGKILL) ## line 9 ##
327+
**********************************************************************
317328
----------------------------------------------------------------------
318329
sage -t --warn-long 0.0 --random-seed=0 fail_and_die.rst # Killed due to kill signal
319330
----------------------------------------------------------------------
320331
...
332+
sage: proc.returncode
321333
16
322334
323335
Test that ``sig_on_count`` is checked correctly::
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
The :exc:`NameError` raised on the second line should be displayed, even
2-
if we crash immediately afterwards::
2+
if we crash immediately afterwards (also test printing of line continuation)::
33

44
sage: import time, signal
5+
sage: print(1,
6+
....: 2)
7+
1 2
58
sage: this_gives_a_NameError
69
sage: os.kill(os.getpid(), signal.SIGKILL)

0 commit comments

Comments
 (0)