[m-rev.] for review: Add test for mdb 'list' external command.

Peter Wang novalazy at gmail.com
Tue Oct 6 12:38:29 AEDT 2020


tests/debugger/list_cmd.m:
tests/debugger/list_cmd.inp:
tests/debugger/list_cmd.exp:
tests/debugger/list_cmd.exp2:
    Add new test case.

tests/debugger/list_cmd.sh:
    Add script to be set as the 'list_cmd'.

tests/debugger/Mmakefile:
    Enable the new test.
---
 tests/debugger/Mmakefile     |  4 ++++
 tests/debugger/list_cmd.exp  | 14 ++++++++++++++
 tests/debugger/list_cmd.exp2 | 10 ++++++++++
 tests/debugger/list_cmd.inp  |  5 +++++
 tests/debugger/list_cmd.m    | 36 ++++++++++++++++++++++++++++++++++++
 tests/debugger/list_cmd.sh   | 29 +++++++++++++++++++++++++++++
 6 files changed, 98 insertions(+)
 create mode 100644 tests/debugger/list_cmd.exp
 create mode 100644 tests/debugger/list_cmd.exp2
 create mode 100644 tests/debugger/list_cmd.inp
 create mode 100644 tests/debugger/list_cmd.m
 create mode 100755 tests/debugger/list_cmd.sh

diff --git a/tests/debugger/Mmakefile b/tests/debugger/Mmakefile
index ed83f1137..1d9b7ec56 100644
--- a/tests/debugger/Mmakefile
+++ b/tests/debugger/Mmakefile
@@ -48,6 +48,7 @@ NONRETRY_PROGS = \
 	interpreter			\
 	label_layout			\
 	lambdatest			\
+	list_cmd			\
 	loopcheck			\
 	lval_desc_array			\
 	mdbrc_test			\
@@ -445,6 +446,9 @@ label_layout.out: label_layout label_layout.inp
 lambdatest.out: lambdatest lambdatest.inp
 	$(MDB_STD) ./lambdatest < lambdatest.inp > lambdatest.out 2>&1
 
+list_cmd.out: list_cmd list_cmd.inp
+	$(MDB) ./list_cmd < list_cmd.inp > list_cmd.out 2>&1
+
 loopcheck.out: loopcheck loopcheck.$(INP)
 	if $(MDB) ./loopcheck < loopcheck.$(INP)		\
 		> loopcheck.tmp 2>&1;				\
diff --git a/tests/debugger/list_cmd.exp b/tests/debugger/list_cmd.exp
new file mode 100644
index 000000000..8a47d998f
--- /dev/null
+++ b/tests/debugger/list_cmd.exp
@@ -0,0 +1,14 @@
+       1:      1  1 CALL pred list_cmd.main/2-0 (det) list_cmd.m:22
+mdb> echo on
+Command echo enabled.
+mdb> list_cmd ./list_cmd.sh
+mdb> step
+       2:      2  2 CALL pred list_cmd.fib/2-0 (det) list_cmd.m:29 (list_cmd.m:23)
+mdb> list
+ 27 :- pred fib(int::in, int::out) is det.
+ 28 
+*29 fib(N, F) :-
+ 30     ( if N < 2 then
+ 31         F = 1
+mdb> continue -n
+8
diff --git a/tests/debugger/list_cmd.exp2 b/tests/debugger/list_cmd.exp2
new file mode 100644
index 000000000..6d5ae85ef
--- /dev/null
+++ b/tests/debugger/list_cmd.exp2
@@ -0,0 +1,10 @@
+       1:      1  1 CALL pred list_cmd.main/2-0 (det) list_cmd.m:22
+mdb> echo on
+Command echo enabled.
+mdb> list_cmd ./list_cmd.sh
+mdb> step
+       2:      2  2 CALL pred list_cmd.fib/2-0 (det) list_cmd.m:29 (list_cmd.m:23)
+mdb> list
+mdb: ./list_cmd.sh: posix_spawn not supported on this platform
+mdb> continue -n
+8
diff --git a/tests/debugger/list_cmd.inp b/tests/debugger/list_cmd.inp
new file mode 100644
index 000000000..9d6b92624
--- /dev/null
+++ b/tests/debugger/list_cmd.inp
@@ -0,0 +1,5 @@
+echo on
+list_cmd ./list_cmd.sh
+step
+list
+continue -n
diff --git a/tests/debugger/list_cmd.m b/tests/debugger/list_cmd.m
new file mode 100644
index 000000000..a2d89326b
--- /dev/null
+++ b/tests/debugger/list_cmd.m
@@ -0,0 +1,36 @@
+%---------------------------------------------------------------------------%
+% vim: ts=4 sw=4 et ft=mercury
+%---------------------------------------------------------------------------%
+%
+% The .exp file is for platforms with posix_spawn.
+% The .exp2 file is for platforms without posix_spawn.
+%
+%---------------------------------------------------------------------------%
+
+:- module list_cmd.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module int.
+
+main(!IO) :-
+    fib(5, N),
+    io.write_int(N, !IO),
+    io.nl(!IO).
+
+:- pred fib(int::in, int::out) is det.
+
+fib(N, F) :-
+    ( if N < 2 then
+        F = 1
+    else
+        fib(N - 1, F1),
+        fib(N - 2, F2),
+        F = F1 + F2
+    ).
diff --git a/tests/debugger/list_cmd.sh b/tests/debugger/list_cmd.sh
new file mode 100755
index 000000000..de3f59ea0
--- /dev/null
+++ b/tests/debugger/list_cmd.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+#---------------------------------------------------------------------------#
+# vim: ts=4 sw=4 expandtab ft=sh
+#---------------------------------------------------------------------------#
+# Copyright (C) 2020 The Mercury team.
+# This file may only be copied under the terms of the GNU General
+# Public License - see the file COPYING in the Mercury distribution.
+#---------------------------------------------------------------------------#
+#
+# list_cmd.sh <source-file> <first-line> <last-line> <mark-line>
+#
+
+SCRIPT='
+NR >= first_line && NR <= last_line {
+    if (NR == mark_line) {
+        print "*" NR, $0;
+    } else {
+        print " " NR, $0;
+    }
+}' 
+
+exec awk \
+    -v first_line="$2" \
+    -v last_line="$3" \
+    -v mark_line="$4" \
+    "${SCRIPT}" \
+    "$1"
+
+#-----------------------------------------------------------------------------#
-- 
2.28.0



More information about the reviews mailing list