summaryrefslogtreecommitdiff
path: root/regress/lib/libedit
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-06-01 16:29:01 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-06-01 16:29:01 +0000
commitb23ee8d4e43bcfbb6a2788954addef53dcff6e22 (patch)
tree45c5ba5016a2d88952d54edd068af9f7c41c68c9 /regress/lib/libedit
parentdb807cf5bb469cbfa3d29d891911c5bd56cb471f (diff)
Test history_get() return value;
from Bastian Maerkisch <bmaerkisch at web dot de>.
Diffstat (limited to 'regress/lib/libedit')
-rw-r--r--regress/lib/libedit/readline/history.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/regress/lib/libedit/readline/history.c b/regress/lib/libedit/readline/history.c
index 57001e7eb61..8afbe5a022f 100644
--- a/regress/lib/libedit/readline/history.c
+++ b/regress/lib/libedit/readline/history.c
@@ -82,6 +82,32 @@ test_where(void)
}
+/*
+ * Fails if the argument of history_get()
+ * does not refer to the zero-based index + history_base.
+ */
+int
+test_get(void)
+{
+ HIST_ENTRY *he;
+ int ok = 1;
+
+ using_history();
+ add_history("111");
+ add_history("222");
+ add_history("333");
+ add_history("444");
+
+ /* Try to retrieve second element. */
+ he = history_get(history_base + 1);
+ if (he == NULL || he->line == NULL || strcmp(he->line, "222") != 0)
+ ok = 0;
+
+ clear_history();
+ return ok;
+}
+
+
/* Fails if set_pos returns 0 for success and -1 for failure. */
int
test_set_pos_return_values(void)
@@ -243,6 +269,10 @@ main(void)
warnx("where returns the wrong history number.");
fail++;
}
+ if (!test_get()) {
+ warnx("retrieving elements with history_get failed.");
+ fail++;
+ }
if (!test_set_pos_return_values()) {
warnx("set_pos returns the wrong history number.");
fail++;