diff options
author | Ben Elliston <bje@gnu.org> | 2008-04-07 14:48:21 +1000 |
---|---|---|
committer | Ben Elliston <bje@gnu.org> | 2008-04-07 14:49:27 +1000 |
commit | 7cd597d12ffd161206a468963fb791ffa833086e (patch) | |
tree | 0848199f286311055864ea8b82634e34a6ad7b78 /testsuite | |
parent | 7366d4887cca6839218272fc298cd1a1fb708b39 (diff) | |
download | dejagnu-7cd597d12ffd161206a468963fb791ffa833086e.tar.gz dejagnu-7cd597d12ffd161206a468963fb791ffa833086e.tar.bz2 dejagnu-7cd597d12ffd161206a468963fb791ffa833086e.zip |
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.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/libdejagnu/unit.cc | 46 |
1 files changed, 28 insertions, 18 deletions
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 <regex.h> #include <string> #include <fstream> +#include <sstream> #include <set> #include <dejagnu.h> @@ -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; } - |