Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show continuation lines when doctest crashes #39102

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ jobs:
uses: tj-actions/changed-files@v45
with:
# File extensions for doctests per sage.doctest.control.skipfile
# Also src/sage/doctests/tests/ are excluded because of nodoctest file
# which would make sage.doctest.control.skipdir returns True
files_yaml: |
configures:
- 'build/pkgs/*/spkg-configure.m4'
Expand All @@ -118,6 +120,7 @@ jobs:
doctests:
- 'src/**/*.{py,pyx,pxd,pxi,sage,spyx,rst,tex}'
- '!src/{setup,conftest*}.py'
- '!src/sage/doctest/tests/*'

- name: Determine targets to build
id: build-targets
Expand Down Expand Up @@ -246,7 +249,7 @@ jobs:
./sage -python -m pytest -c tox.ini -qq --doctest --collect-only || true
shell: sh .ci/docker-exec-script.sh BUILD /sage {0}

- name: Test changed files (sage -t --new)
- name: Test changed files
if: (success() || failure()) && steps.container.outcome == 'success' && steps.changed-files.outputs.doctests_all_changed_files
run: |
export MAKE="make -j2 --output-sync=recurse" SAGE_NUM_THREADS=4
Expand Down
3 changes: 2 additions & 1 deletion src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ def _run(self, test, compileflags, out):
# We print the example we're running for easier debugging
# if this file times out or crashes.
with OriginalSource(example):
print("sage: " + example.source[:-1] + " ## line %s ##" % (test.lineno + example.lineno + 1))
assert example.source.endswith("\n"), example
print("sage: " + example.source[:-1].replace("\n", "\n....: ") + " ## line %s ##" % (test.lineno + example.lineno + 1))
# Update the position so that result comparison works
self._fakeout.getvalue()
if not quiet:
Expand Down
23 changes: 18 additions & 5 deletions src/sage/doctest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,21 @@
...
16

A different kind of crash::
A different kind of crash (also test printing of line continuation ``...:``,
represented by ``<DOTSCOLON>`` below)::

sage: subprocess.call(["sage", "-t", "--warn-long", "0", # long time
....: "--random-seed=0", "--optional=sage", "fail_and_die.rst"], **kwds)
sage: # long time
sage: proc = subprocess.run(["sage", "-t", "--warn-long", "0",
....: "--random-seed=0", "--optional=sage", "fail_and_die.rst"], **kwds,
....: stdout=subprocess.PIPE, text=True)
sage: # the replacements are needed to avoid the strings being interpreted
....: # specially by the doctesting framework
sage: print(proc.stdout.replace('sage:', 'sage<COLON>').replace('....:', '<DOTSCOLON>'))
Running doctests...
Doctesting 1 file.
sage -t --warn-long 0.0 --random-seed=0 fail_and_die.rst
**********************************************************************
File "fail_and_die.rst", line 5, in sage.doctest.tests.fail_and_die
File "fail_and_die.rst", line 8, in sage.doctest.tests.fail_and_die
Failed example:
this_gives_a_NameError
Exception raised:
Expand All @@ -313,11 +319,18 @@
Killed due to kill signal
**********************************************************************
Tests run before process (pid=...) failed:
...
sage<COLON> import time, signal ## line 4 ##
sage<COLON> print(1,
<DOTSCOLON> 2) ## line 5 ##
1 2
sage<COLON> this_gives_a_NameError ## line 8 ##
sage<COLON> os.kill(os.getpid(), signal.SIGKILL) ## line 9 ##
**********************************************************************
----------------------------------------------------------------------
sage -t --warn-long 0.0 --random-seed=0 fail_and_die.rst # Killed due to kill signal
----------------------------------------------------------------------
...
sage: proc.returncode
16

Test that ``sig_on_count`` is checked correctly::
Expand Down
5 changes: 4 additions & 1 deletion src/sage/doctest/tests/fail_and_die.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
The :exc:`NameError` raised on the second line should be displayed, even
if we crash immediately afterwards::
if we crash immediately afterwards (also test printing of line continuation)::

sage: import time, signal
sage: print(1,
....: 2)
1 2
sage: this_gives_a_NameError
sage: os.kill(os.getpid(), signal.SIGKILL)
Loading