From 4f8c6333beca60b42867d320704b74f26eeebfc7 Mon Sep 17 00:00:00 2001 From: Sergei Mironov Date: Fri, 20 Dec 2024 02:01:55 +0400 Subject: [PATCH] Fix and test --irreproducible-exitcode --- python/litrepl/base.py | 10 +++++----- python/litrepl/main.py | 3 +++ sh/runtests.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/python/litrepl/base.py b/python/litrepl/base.py index e99884c..5c10f50 100644 --- a/python/litrepl/base.py +++ b/python/litrepl/base.py @@ -513,10 +513,9 @@ def resultsec(self,tree): emarker=tree.children[2].children[0].value bm,em=tree.children[0].meta,tree.children[2].meta if (es.nsec in nsecs) and (es.nsec in es.sres): - t2=bmarker+"\n"+indent(bm.column-1, - escape(es.sres[es.nsec],emarker)+emarker) + t2="\n"+indent(bm.column-1,escape(es.sres[es.nsec],emarker)) es.ledder[bm.line]=nlines(t2)-nlines(t) - self._print(t2) + self._print(bmarker+t2+emarker) if a.irreproducible_exitcode and t!=t2: pstderr(f"Result mismatch:\nExisting:\n{t}\nNew:\n{t2}") es.ecodes[es.nsec]=a.irreproducible_exitcode @@ -559,9 +558,10 @@ def _finally(): with with_parent_finally(_finally): C().visit(tree) - pdebug(f"eval_code_ ecodes {es.ecodes}") - return max(map(lambda x:ECODE_OK if x is None else x, + ec=max(map(lambda x:ECODE_OK if x is None else x, es.ecodes.values()),default=ECODE_OK) + pdebug(f"eval_code_ ecodes {es.ecodes} => {ec}") + return ec def solve_cpos(tree, cs:List[CursorPos])->PrepInfo: """ Preprocess the document tree. Resolve the list of cursor locations `cs` diff --git a/python/litrepl/main.py b/python/litrepl/main.py index 1ad3a10..1d0bb46 100644 --- a/python/litrepl/main.py +++ b/python/litrepl/main.py @@ -172,6 +172,9 @@ def main(args=None): if a.pending_exitcode: a.pending_exitcode=int(a.pending_exitcode) + if a.irreproducible_exitcode: + a.irreproducible_exitcode=int(a.irreproducible_exitcode) + if a.result_textwidth: a.result_textwidth=int(a.result_textwidth) if a.result_textwidth==0: diff --git a/sh/runtests.sh b/sh/runtests.sh index ff3ba61..768d4d9 100755 --- a/sh/runtests.sh +++ b/sh/runtests.sh @@ -1256,6 +1256,42 @@ EOF )} #}}} +test_irreproducible() {( #{{{ +mktest "_test_irreproducible" +runlitrepl start python +cat >source.md <<"EOF" +``` python +3+4 +``` +``` result +6 +``` +``` python +1+3 +``` +``` result +5 +``` +EOF +cat source.md | runlitrepl --irreproducible-exitcode=33 eval-sections >out.md 2>err.txt || test "$?" = 33 +grep -q 'mismatch' err.txt +diff -u out.md - <<"EOF" +``` python +3+4 +``` +``` result +7 +``` +``` python +1+3 +``` +``` result +4 +``` +EOF +)} +#}}} + die() { echo "$@" >&2 exit 1 @@ -1320,6 +1356,7 @@ tests() { echo test_vim_eval_selection $(which python) - - echo test_vim_ai_query - $(which aicli) - echo test_interp_disabled $(which python) - $(which sh) + echo test_irreproducible $(which ipython) - - } runlitrepl() { @@ -1332,6 +1369,7 @@ runlitrepl() { unset LITREPL_WORKDIR test -n "$LITREPL_TEST_PYTHON_INTERPRETER" test -n "$LITREPL_TEST_AI_INTERPRETER" + test -n "$LITREPL_TEST_SH_INTERPRETER" test -n "$LITREPL_BIN" $LITREPL_BIN/litrepl --debug="$LITREPL_DEBUG" \ --python-interpreter="$LITREPL_TEST_PYTHON_INTERPRETER" \