diff --git a/tests/.gitignore b/tests/.gitignore index 5c05d9d..d93c979 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -6,4 +6,8 @@ # this notice are preserved. This file is offered as-is, without any warranty. # +*.log +*.sum +site.bak +site.exp tcsgrep diff --git a/tests/Makefile.am b/tests/Makefile.am index ab2676d..0719ceb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,7 +6,12 @@ # this notice are preserved. This file is offered as-is, without any warranty. # -AM_CPPFLAGS = -I$(top_srcdir)/src +AUTOMAKE_OPTIONS = dejagnu +AM_CPPFLAGS = -I$(top_srcdir)/src + noinst_PROGRAMS = tcsgrep tcsgrep_SOURCES = tcsgrep.c tcsgrep_LDADD = $(top_srcdir)/src/libctlseqs.la + +RUNTESTDEFAULTFLAGS = TCSGREP_BIN=$(srcdir)/tcsgrep +EXTRA_DEJAGNU_SITE_CONFIG = $(srcdir)/init.exp diff --git a/tests/ctlseqs/match.exp b/tests/ctlseqs/match.exp new file mode 100644 index 0000000..239c143 --- /dev/null +++ b/tests/ctlseqs/match.exp @@ -0,0 +1,43 @@ +# +# Copyright (C) 2021 CismonX +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty, provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +# + +set tool ctlseqs +set timeout 2 + +set n1 [ expr int(rand()*5000) ] +set n2 [ expr int(rand()*5000) ] +set n3 [ expr int(rand()*5000) ] + +set input { } +lappend input "$CSI$n1;${n2}H" +lappend input "$DCS$n1;$n2|$n3$ST" +lappend input "$CSI +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty, provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +# diff --git a/tests/ctlseqs/partial.exp b/tests/ctlseqs/partial.exp new file mode 100644 index 0000000..174ea3e --- /dev/null +++ b/tests/ctlseqs/partial.exp @@ -0,0 +1,7 @@ +# +# Copyright (C) 2021 CismonX +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty, provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +# diff --git a/tests/ctlseqs/timeout.exp b/tests/ctlseqs/timeout.exp new file mode 100644 index 0000000..174ea3e --- /dev/null +++ b/tests/ctlseqs/timeout.exp @@ -0,0 +1,7 @@ +# +# Copyright (C) 2021 CismonX +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty, provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +# diff --git a/tests/init.exp b/tests/init.exp new file mode 100644 index 0000000..b3c1d1e --- /dev/null +++ b/tests/init.exp @@ -0,0 +1,44 @@ +# +# Copyright (C) 2021 CismonX +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty, provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +# + +proc tcsgrep_start args { + global TCSGREP_BIN + set run_cmd [ list $TCSGREP_BIN "-t500" ] + foreach arg $args { + lappend run_cmd [ + switch -regexp -matchvar value -- $arg { + verbose { lindex "-v" } + purge { lindex "-p" } + limit=(\\d+) { lindex "-l[lindex $value 1]" } + } + ] + } + set stty_init { raw -echo } + global spawn_id + spawn {*}$run_cmd +} + +proc tcsgrep_stop { } { + global spawn_id + send \x04 + expect { + -ex "NOSEQ 1 EOT\n" { } + default { + fail "program exited unexpectedly" + } + } + catch wait result + if { [ set exit_code [ lindex $result 3 ] ] } { + fail "program exited with code $exit_code" + } +} + +set ESC "\x1b" +set CSI "$ESC\[" +set DCS "${ESC}P" +set ST "$ESC\\" diff --git a/tests/tcsgrep.c b/tests/tcsgrep.c index 0dd9ccf..6fe340e 100644 --- a/tests/tcsgrep.c +++ b/tests/tcsgrep.c @@ -439,7 +439,7 @@ main(int argc, char **argv) } case CTLSEQS_NOSEQ: print_generic_seq("NOSEQ", result, true); - if (result[1].str[0] == 0x04) { + if (!ctx.not_tty && result[1].str[0] == 0x04) { goto terminate; } break;