diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bbecdf481b6..5e3143ffbb9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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' @@ -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 @@ -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 diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 962c21e12cd..fe173cfb7a1 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -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: diff --git a/src/sage/doctest/test.py b/src/sage/doctest/test.py index a6aa893bb22..bbfa3acef01 100644 --- a/src/sage/doctest/test.py +++ b/src/sage/doctest/test.py @@ -295,15 +295,21 @@ ... 16 -A different kind of crash:: +A different kind of crash (also test printing of line continuation ``...:``, +represented by ```` 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').replace('....:', '')) 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: @@ -313,11 +319,18 @@ Killed due to kill signal ********************************************************************** Tests run before process (pid=...) failed: - ... + sage import time, signal ## line 4 ## + sage print(1, + 2) ## line 5 ## + 1 2 + sage this_gives_a_NameError ## line 8 ## + sage 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:: diff --git a/src/sage/doctest/tests/fail_and_die.rst b/src/sage/doctest/tests/fail_and_die.rst index 65e652f4f5e..d2a72d5d9d6 100644 --- a/src/sage/doctest/tests/fail_and_die.rst +++ b/src/sage/doctest/tests/fail_and_die.rst @@ -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)