From a4e78e8d2942b5ab96d55c2392e469b84a9a4217 Mon Sep 17 00:00:00 2001 From: Ben Elliston Date: Mon, 7 Apr 2008 14:48:21 +1000 Subject: Make the testsuite work better. * Makefile.am (RUNTESTDEFAULTFLAGS): Add RUNTEST=$(RUNTEST). * Makefile.in: Regenerate. * dejagnu.exp (host_execute): Improve regexp matching. * testsuite/libdejagnu/unit.cc: C++ fixes. --- ChangeLog | 7 +++++++ Makefile.am | 2 +- Makefile.in | 2 +- lib/dejagnu.exp | 18 ++++++++++------- testsuite/libdejagnu/unit.cc | 46 +++++++++++++++++++++++++++----------------- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index c72ffd0..2af5aa3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-04-06 Daniel Jacobowitz + * Makefile.am (RUNTESTDEFAULTFLAGS): Add RUNTEST=$(RUNTEST). + * Makefile.in: Regenerate. + * dejagnu.exp (host_execute): Improve regexp matching. + * testsuite/libdejagnu/unit.cc: C++ fixes. + +2008-04-06 Daniel Jacobowitz + * lib/utils.exp (diff): Open both files as binary. 2008-04-06 Daniel Jacobowitz diff --git a/Makefile.am b/Makefile.am index 0e51659..c027bcd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -195,7 +195,7 @@ TESTSUITE_FILES = \ testsuite/libdejagnu/tunit.exp RUNTEST = ${top_srcdir}/runtest -RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite +RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite RUNTEST=$(RUNTEST) AM_CXXFLAGS = -I$(top_srcdir) -g check_PROGRAMS = unit diff --git a/Makefile.in b/Makefile.in index 2956ee8..2ff7f25 100644 --- a/Makefile.in +++ b/Makefile.in @@ -396,7 +396,7 @@ TESTSUITE_FILES = \ testsuite/libdejagnu/tunit.exp RUNTEST = ${top_srcdir}/runtest -RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite +RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite RUNTEST=$(RUNTEST) AM_CXXFLAGS = -I$(top_srcdir) -g unit_SOURCES = testsuite/libdejagnu/unit.cc diff --git a/lib/dejagnu.exp b/lib/dejagnu.exp index a293f2f..a764aa5 100755 --- a/lib/dejagnu.exp +++ b/lib/dejagnu.exp @@ -133,49 +133,50 @@ proc host_execute {args} { # test case. # spawn -noecho -open [open "|./${executable}" "r"] spawn -noecho "./${executable}" ${params} + set prefix "\[^\r\n\]*" expect { - -re "\[0-9\]\[0-9\]:..:..:${text}\r\n" { + -re "^$prefix\[0-9\]\[0-9\]:..:..:${text}*\r\n" { regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output verbose "$output" 3 set timetol 0 exp_continue } - -re "NOTE:${text}*" { + -re "^$prefix\tNOTE:${text}*" { regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output set output [string range $output 6 end] verbose "$output" 2 set timetol 0 exp_continue } - -re "PASSED:${text}*" { + -re "^$prefix\tPASSED:${text}*" { regsub "\[\n\r\t\]*PASSED: $text\r\n" $expect_out(0,string) "" output set output [string range $output 8 end] pass "$output" set timetol 0 exp_continue } - -re "FAILED:${text}*" { + -re "^$prefix\tFAILED:${text}*" { regsub "\[\n\r\t\]*FAILED: $text\r\n" $expect_out(0,string) "" output set output [string range $output 8 end] fail "$output" set timetol 0 exp_continue } - -re "UNTESTED:${text}*" { + -re "^$prefix\tUNTESTED:${text}*" { regsub "\[\n\r\t\]*TESTED: $text\r\n" $expect_out(0,string) "" output set output [string range $output 8 end] untested "$output" set timetol 0 exp_continue } - -re "UNRESOLVED:${text}*" { + -re "^$prefix\tUNRESOLVED:${text}*" { regsub "\[\n\r\t\]*UNRESOLVED: $text\r\n" $expect_out(0,string) "" output set output [string range $output 8 end] unresolved "$output" set timetol 0 exp_continue } - -re "Totals" { + -re "^Totals" { verbose "All done" 2 } eof { @@ -193,6 +194,9 @@ proc host_execute {args} { return "Timed out executing test case" } } + -re "^$prefix\r\n" { + exp_continue + } } # force a close of the executable to be safe. diff --git a/testsuite/libdejagnu/unit.cc b/testsuite/libdejagnu/unit.cc index d6e08a9..841d6f0 100644 --- a/testsuite/libdejagnu/unit.cc +++ b/testsuite/libdejagnu/unit.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -56,17 +57,14 @@ main (int argc, char *argv[]) { regex_t regex_pat; outstate = os1; + stringstream strbuf; + streambuf *pbuf; // Replace the output buffer for cout, so we can examine it to see // what was displayed. Otherwise, there is no way we can test the // logging functions completely. - char buf[5120]; -#ifdef __STDC_HOSTED__ - cout.rdbuf ()->pubsetbuf (buf, 5120); -#else - cout.rdbuf ()->setbuf (buf, 5120); -#endif - + pbuf = cout.rdbuf (); + testClass1.tname = "testType1"; testClass1.tnum = 1; testClass2.tname = "testType2"; @@ -75,50 +73,63 @@ main (int argc, char *argv[]) testClass3.tnum = 3; // Test the pass message. + cout.rdbuf (strbuf.rdbuf ()); + strbuf.str (""); test.pass ("bogus pass message for testing"); outstate = os2; - if (strncmp (buf, "\tPAS: bogus pass message", 22) == 0) + cout.rdbuf (pbuf); + if (strncmp (strbuf.str().c_str(), "\tPAS: bogus pass message", 22) == 0) runtest.pass ("Pass message"); else runtest.fail ("Pass message"); // Test the fail message. + cout.rdbuf (strbuf.rdbuf ()); + strbuf.str (""); outstate = os1; test.fail ("bogus fail message for testing"); - cout.flush (); + cout.rdbuf (pbuf); outstate = os2; - if (strncmp (buf, "\tFAI: bogus fail message", 22) == 0) + if (strncmp (strbuf.str().c_str(), "\tFAI: bogus fail message", 22) == 0) runtest.pass ("Fail message"); else runtest.fail ("Fail message"); // Test the untested message. + cout.rdbuf (strbuf.rdbuf ()); + strbuf.str (""); outstate = os1; test.untested ("bogus untested message for testing"); - cout.flush (); + cout.rdbuf (pbuf); outstate = os2; - if (strncmp (buf, "\tUNT: bogus untested message", 21) == 0) { + if (strncmp (strbuf.str().c_str(), "\tUNT: bogus untested message", 21) == 0) { runtest.pass ("Untested message"); } else { runtest.fail ("Untested message"); } // Test the unresolved message. + cout.rdbuf (strbuf.rdbuf ()); + strbuf.str (""); outstate = os1; test.unresolved ("bogus unresolved message for testing"); - cout.flush (); + cout.rdbuf (pbuf); outstate = os2; - if (strncmp (buf, "\tUNR: bogus unresolved message", 21) == 0) + if (strncmp (strbuf.str().c_str(), "\tUNR: bogus unresolved message", 21) == 0) runtest.pass ("Unresolved message"); else runtest.fail ("Unresolved message"); // Make sure we got everything in the totals. + cout.rdbuf (strbuf.rdbuf ()); + strbuf.str (""); regcomp (®ex_pat, - "\r\n\t#passed.*#failed.*#untested.*#unresolved", - REG_NOSUB | REG_NEWLINE); + "\t#passed.*#real failed.*#untested.*#unresolved", + REG_NOSUB); - if (regexec (®ex_pat, buf, 0, (regmatch_t *) 0, 0)) + test.totals (); + cout.rdbuf (pbuf); + if (regexec (®ex_pat, strbuf.str().c_str(), 0, (regmatch_t *) 0, 0) == 0) runtest.pass ("Totals message"); else runtest.fail ("Totals message"); @@ -126,4 +137,3 @@ main (int argc, char *argv[]) return 0; } - -- cgit v1.1