Skip to content

Commit

Permalink
Fix and test --irreproducible-exitcode
Browse files Browse the repository at this point in the history
sergei-mironov committed Dec 19, 2024
1 parent f63a1af commit 4f8c633
Showing 3 changed files with 46 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/litrepl/base.py
Original file line number Diff line number Diff line change
@@ -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`
3 changes: 3 additions & 0 deletions python/litrepl/main.py
Original file line number Diff line number Diff line change
@@ -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:
38 changes: 38 additions & 0 deletions sh/runtests.sh
Original file line number Diff line number Diff line change
@@ -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" \

0 comments on commit 4f8c633

Please sign in to comment.