summaryrefslogtreecommitdiff
path: root/regress/lib/libedit/read
diff options
context:
space:
mode:
Diffstat (limited to 'regress/lib/libedit/read')
-rw-r--r--regress/lib/libedit/read/Makefile14
-rw-r--r--regress/lib/libedit/read/exp_getcmd.txt3
-rw-r--r--regress/lib/libedit/read/glue.c62
-rw-r--r--regress/lib/libedit/read/test_getcmd.c102
-rw-r--r--regress/lib/libedit/read/test_read_char.c38
5 files changed, 177 insertions, 42 deletions
diff --git a/regress/lib/libedit/read/Makefile b/regress/lib/libedit/read/Makefile
index 5f4539e2251..9799eb1fa6b 100644
--- a/regress/lib/libedit/read/Makefile
+++ b/regress/lib/libedit/read/Makefile
@@ -1,18 +1,22 @@
-# $OpenBSD: Makefile,v 1.1 2016/02/11 15:37:20 schwarze Exp $
+# $OpenBSD: Makefile,v 1.2 2016/03/01 16:12:11 schwarze Exp $
#
# Author: Ingo Schwarze <schwarze@openbsd.org>, 2016. Public Domain.
#
# Run "cd /usr/src/lib/libedit && make obj && make depend" first.
-REGRESS_TARGETS = check
+REGRESS_TARGETS = getcmd
+#REGRESS_TARGETS += read_char
-PROG = test_read_char
CPPFLAGS += -DWIDECHAR
CPPFLAGS += -I${.CURDIR}/../../../../lib/libedit
CPPFLAGS += -I${.OBJDIR}/../../../../lib/libedit
-MAN =
+CLEANFILES += test_read_char test_getcmd out_getcmd.txt
-check:
+read_char: test_read_char
sh ${.CURDIR}/test_read_char.sh
+getcmd: test_getcmd
+ echo -n s | ./test_getcmd > out_getcmd.txt
+ diff -u ${.CURDIR}/exp_getcmd.txt out_getcmd.txt
+
.include <bsd.regress.mk>
diff --git a/regress/lib/libedit/read/exp_getcmd.txt b/regress/lib/libedit/read/exp_getcmd.txt
new file mode 100644
index 00000000000..5dd9e58e6f1
--- /dev/null
+++ b/regress/lib/libedit/read/exp_getcmd.txt
@@ -0,0 +1,3 @@
+OK insert L'i' macro[0]=ic(1)
+OK command L'c'
+EOF
diff --git a/regress/lib/libedit/read/glue.c b/regress/lib/libedit/read/glue.c
new file mode 100644
index 00000000000..b3ad35dd24d
--- /dev/null
+++ b/regress/lib/libedit/read/glue.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Glue for unit tests of libedit/read.c.
+ * Rather than linking in all the various libedit modules,
+ * provide dummies for those functions called in read.c.
+ */
+
+#define EL EditLine *el __attribute__((__unused__))
+#define UU __attribute__((__unused__))
+
+int ch_enlargebufs(EL, size_t addlen UU) { return 1; }
+void ch_reset(EL, int mclear UU) { }
+void el_resize(EL) { }
+int el_set(EL, int op UU, ...) { return 0; }
+int el_wset(EL, int op UU, ...) { return 0; }
+void re_clear_display(EL) { }
+void re_clear_lines(EL) { }
+void re_refresh(EL) { }
+void re_refresh_cursor(EL) { }
+void sig_clr(EL) { }
+void sig_set(EL) { }
+void terminal__flush(EL) { }
+void terminal_beep(EL) { }
+int tty_cookedmode(EL) { return 0; }
+int tty_rawmode(EL) { return 0; }
+
+int
+keymacro_get(EL, Char *ch, keymacro_value_t *val)
+{
+ static Char value[] = L"ic";
+
+ switch (*ch) {
+ case L'c':
+ val->cmd = ED_COMMAND;
+ return XK_CMD;
+ case L's':
+ val->str = value;
+ return XK_STR;
+ default:
+ val->str = NULL;
+ *ch = '\0';
+ return XK_STR;
+ }
+}
+
+#undef EL
+#undef UU
diff --git a/regress/lib/libedit/read/test_getcmd.c b/regress/lib/libedit/read/test_getcmd.c
new file mode 100644
index 00000000000..1692099717c
--- /dev/null
+++ b/regress/lib/libedit/read/test_getcmd.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "read.c"
+#include "glue.c"
+
+#define N_KEYS 256
+
+/*
+ * Unit test steering program for editline/read.c, read_getcmd().
+ */
+
+int
+main()
+{
+ EditLine el;
+ c_macro_t *ma;
+ int irc;
+ Char ch;
+ el_action_t cmdnum;
+
+ if (setlocale(LC_CTYPE, "") == NULL)
+ err(1, "setlocale");
+
+ el.el_errno = ENOMSG;
+ el.el_flags = CHARSET_IS_UTF8;
+ el.el_infd = STDIN_FILENO;
+
+ el.el_map.alt = NULL;
+ if ((el.el_map.key = calloc(N_KEYS, sizeof(el_action_t))) == NULL)
+ err(1, NULL);
+ el.el_map.key[(unsigned char)'c'] = ED_SEQUENCE_LEAD_IN;
+ el.el_map.key[(unsigned char)'i'] = ED_INSERT;
+ el.el_map.key[(unsigned char)'s'] = ED_SEQUENCE_LEAD_IN;
+ el.el_map.current = el.el_map.key;
+ if ((el.el_signal = calloc(1, sizeof(*el.el_signal))) == NULL)
+ err(1, NULL);
+
+ ma = &el.el_chared.c_macro;
+ ma->level = -1;
+ ma->offset = 0;
+ if ((ma->macro = calloc(EL_MAXMACRO, sizeof(*ma->macro))) == NULL)
+ err(1, NULL);
+
+ if (read_init(&el) != 0)
+ err(1, "read_init");
+
+ do {
+ irc = read_getcmd(&el, &cmdnum, &ch);
+ switch (irc) {
+ case OKCMD:
+ fputs("OK ", stdout);
+ switch (cmdnum) {
+ case ED_COMMAND:
+ fputs("command", stdout);
+ break;
+ case ED_INSERT:
+ fputs("insert", stdout);
+ break;
+ default:
+ printf("cmdnum=%u", cmdnum);
+ break;
+ }
+ printf(" L'%lc'", ch);
+ break;
+ case 0:
+ fputs("EOF", stdout);
+ break;
+ default:
+ printf("ret(%d)", irc);
+ break;
+ }
+ if (el.el_errno != 0)
+ printf(" el_errno=%d", el.el_errno);
+ if (ma->level > -1)
+ printf(" macro[%d]=%ls(%d)", ma->level,
+ *ma->macro, ma->offset);
+ putchar('\n');
+ } while (irc);
+
+ return 0;
+}
diff --git a/regress/lib/libedit/read/test_read_char.c b/regress/lib/libedit/read/test_read_char.c
index 75184edac40..5aab7dbed2b 100644
--- a/regress/lib/libedit/read/test_read_char.c
+++ b/regress/lib/libedit/read/test_read_char.c
@@ -20,43 +20,7 @@
#include <stdlib.h>
#include "read.c"
-
-/*
- * Glue for unit tests of libedit/read.c.
- * Rather than linking in all the various libedit modules,
- * provide dummies for those functions called in read.c.
- * Most aren't actually called in read_char().
- * Requires "make obj && make depend" in src/lib/libedit.
- */
-
-#define EL EditLine *el __attribute__((__unused__))
-#define UU __attribute__((__unused__))
-
-int ch_enlargebufs(EL, size_t addlen UU) { return 1; }
-void ch_reset(EL, int mclear UU) { }
-void el_resize(EL) { }
-int el_set(EL, int op UU, ...) { return 0; }
-void re_clear_display(EL) { }
-void re_clear_lines(EL) { }
-void re_refresh(EL) { }
-void re_refresh_cursor(EL) { }
-void sig_clr(EL) { }
-void sig_set(EL) { }
-void terminal__flush(EL) { }
-void terminal_beep(EL) { }
-int tty_cookedmode(EL) { return 0; }
-int tty_rawmode(EL) { return 0; }
-
-int
-keymacro_get(EL, Char *ch, keymacro_value_t *val)
-{
- val->str = NULL;
- *ch = '\0';
- return XK_STR;
-}
-
-#undef EL
-#undef UU
+#include "glue.c"
/*
* Unit test steering program for editline/read.c, read_char().