From 35913de915ce66581018efccc1d1627bb2d2e667 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 10 Dec 2024 00:13:28 +0700 Subject: [PATCH 1/5] Show continuation lines when doctest crashes --- src/sage/doctest/forker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index bf6d49906de..47afec7dd4d 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -652,7 +652,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: From 4684a36b453c9e8bd4fb7f2fdeb4e69165db08c6 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:39:04 +0700 Subject: [PATCH 2/5] Add a test --- src/sage/doctest/test.py | 20 ++++++++++++++++---- src/sage/doctest/tests/fail_and_die.rst | 5 ++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/sage/doctest/test.py b/src/sage/doctest/test.py index a6aa893bb22..8f1713a13e7 100644 --- a/src/sage/doctest/test.py +++ b/src/sage/doctest/test.py @@ -297,13 +297,18 @@ A different kind of crash:: - 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 +318,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) From 91f04eedec83e599a6d0f4c3dff9682f325d7348 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:28:49 +0700 Subject: [PATCH 3/5] Fix test-new to ignore doctest/tests --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d17c9e85456..81381d15c8f 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/doctests/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 From 328facdd6d76179bb11447ba27d2882d65b0d4c7 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:35:30 +0700 Subject: [PATCH 4/5] Typo --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81381d15c8f..9803e59baf0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,7 +120,7 @@ jobs: doctests: - 'src/**/*.{py,pyx,pxd,pxi,sage,spyx,rst,tex}' - '!src/{setup,conftest*}.py' - - '!src/sage/doctests/tests/*' + - '!src/sage/doctest/tests/*' - name: Determine targets to build id: build-targets From 9c3f66bc779dca23f4f770511b41ddbef615d855 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 10 Dec 2024 22:01:58 +0700 Subject: [PATCH 5/5] Update documentation --- src/sage/doctest/test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/doctest/test.py b/src/sage/doctest/test.py index 8f1713a13e7..bbfa3acef01 100644 --- a/src/sage/doctest/test.py +++ b/src/sage/doctest/test.py @@ -295,7 +295,8 @@ ... 16 -A different kind of crash:: +A different kind of crash (also test printing of line continuation ``...:``, +represented by ```` below):: sage: # long time sage: proc = subprocess.run(["sage", "-t", "--warn-long", "0",