aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Bachmeyer <jcb@gnu.org>2022-12-20 22:27:28 -0600
committerJacob Bachmeyer <jcb@gnu.org>2022-12-20 22:27:28 -0600
commitd807904c119232226a7f644b6a5ebdbb1ed2a67d (patch)
tree843d387c0656b0c631cea3333ab109a611effba4
parent4d829912f7104d6f96886c1e46c173e9e7478946 (diff)
Add support for reporting errors and warnings in dejagnu.h
-rw-r--r--ChangeLog12
-rw-r--r--dejagnu.h38
-rw-r--r--doc/dejagnu.texi34
-rw-r--r--testsuite/libdejagnu/harness.exp10
-rw-r--r--testsuite/libdejagnu/unit-c.c2
-rw-r--r--testsuite/libdejagnu/unit-ccxxmix.cxx4
-rw-r--r--testsuite/libdejagnu/unit-cxx.cxx2
7 files changed, 101 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d94bda..5dcc40e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2022-12-20 Jacob Bachmeyer <jcb@gnu.org>
+ * dejagnu.h (DG_error, DG_warning): New functions.
+ (TestState::error, TestState::warning): New methods.
+ * doc/dejagnu.texi (C unit testing API): Document new functions.
+ (C++ unit testing API): Document new methods and fix an error:
+ TestState::unsupported does not take varargs.
+ * testsuite/libdejagnu/unit-c.c (main): Add support for testing
+ errors and warnings.
+ * testsuite/libdejagnu/unit-cxx.cxx (main): Likewise.
+ * testsuite/libdejagnu/unit-ccxxmix.cxx (main): Likewise.
+ * testsuite/libdejagnu/harness.exp: Add tests.
+ (test_libdejagnu_unit): Add support for ERROR and WARNING tokens.
+
* doc/dejagnu.texi (DejaGnu unit test protocol): Add ERROR and
WARNING tokens to DejaGnu unit testing protocol.
* lib/dejagnu.exp (host_execute): Implement same.
diff --git a/dejagnu.h b/dejagnu.h
index 282b072..140e3e9 100644
--- a/dejagnu.h
+++ b/dejagnu.h
@@ -177,6 +177,34 @@ note (const char* fmt, ...)
}
static inline void
+DG_error (const char* fmt, ...)
+{
+ va_list ap;
+
+ DG__init ();
+
+ flockfile (stdout);
+ fputs ("\tERROR: ", stdout);
+ va_start (ap, fmt); vfprintf (stdout, fmt, ap); va_end (ap);
+ fputc ('\n', stdout);
+ funlockfile (stdout);
+}
+
+static inline void
+DG_warning (const char* fmt, ...)
+{
+ va_list ap;
+
+ DG__init ();
+
+ flockfile (stdout);
+ fputs ("\tWARNING: ", stdout);
+ va_start (ap, fmt); vfprintf (stdout, fmt, ap); va_end (ap);
+ fputc ('\n', stdout);
+ funlockfile (stdout);
+}
+
+static inline void
totals (void)
{
printf ("\nTotals:\n");
@@ -316,6 +344,16 @@ class TestState {
std::cout << "\t" << "NOTE: " << s << std::endl;
}
+ void error (std::string s)
+ {
+ std::cout << "\t" << "ERROR: " << s << std::endl;
+ }
+
+ void warning (std::string s)
+ {
+ std::cout << "\t" << "WARNING: " << s << std::endl;
+ }
+
void totals (void)
{
std::cout << std::endl << "Totals:" << std::endl;
diff --git a/doc/dejagnu.texi b/doc/dejagnu.texi
index 5b94c0e..43e13f6 100644
--- a/doc/dejagnu.texi
+++ b/doc/dejagnu.texi
@@ -2645,6 +2645,22 @@ facility that is not available in the testing environment.
@end quotation
@item
+@code{DG_error} prints a message for a major but nonfatal error
+detected in a test case.
+
+@quotation
+@t{@b{DG_error}(@i{msg}, ...);}
+@end quotation
+
+@item
+@code{DG_warning} prints a message for a minor error detected in a
+test case.
+
+@quotation
+@t{@b{DG_warning}(@i{msg}, ...);}
+@end quotation
+
+@item
@code{totals} prints out the total counts of all of the test results
as a convenience when running the unit test program directly. DejaGnu
does not use this information and instead counts the results
@@ -2741,7 +2757,23 @@ to look over the results to determine what happened.
facility that is not available in the testing environment.
@quotation
-@t{@b{TestState::unsupported}(@i{msg}, ...);}
+@t{@b{TestState::unsupported}(@i{msg});}
+@end quotation
+
+@item
+@code{error} prints a message for a major but nonfatal error
+detected in a test case.
+
+@quotation
+@t{@b{TestState::error}(@i{msg});}
+@end quotation
+
+@item
+@code{warning} prints a message for a minor error detected in a
+test case.
+
+@quotation
+@t{@b{TestState::warning}(@i{msg});}
@end quotation
@end itemize
diff --git a/testsuite/libdejagnu/harness.exp b/testsuite/libdejagnu/harness.exp
index 34da7b4..c3ec3f5 100644
--- a/testsuite/libdejagnu/harness.exp
+++ b/testsuite/libdejagnu/harness.exp
@@ -88,6 +88,8 @@ proc test_libdejagnu_unit { language tests } {
untested { set expected UNTESTED }
unresolved { set expected UNRESOLVED }
unsupported { set expected UNSUPPORTED }
+ warning { set expected WARNING }
+ error { set expected ERROR }
}
if { [info exists expected_totals([lindex $test $test_idx])]} {
incr expected_totals([lindex $test $test_idx])
@@ -134,6 +136,8 @@ proc test_libdejagnu_unit { language tests } {
foreach language {c cxx} {
test_libdejagnu_unit $language {
note pass fail xpass xfail untested unresolved unsupported
+ {error pass} {error fail} {error xpass} {error xfail}
+ {warning pass} {warning fail} {warning xpass} {warning xfail}
}
}
@@ -141,4 +145,10 @@ test_libdejagnu_unit ccxxmix {
{pass pass xpass xfail xfail xpass}
{fail fail xfail xpass xpass xfail}
{untested unresolved unsupported untested unresolved unsupported}
+ {error pass} {error fail} {error xpass} {error xfail}
+ {warning pass} {warning fail} {warning xpass} {warning xfail}
+ {note error pass} {note error fail}
+ {note error xpass} {note error xfail}
+ {note warning pass} {note warning fail}
+ {note warning xpass} {note warning xfail}
}
diff --git a/testsuite/libdejagnu/unit-c.c b/testsuite/libdejagnu/unit-c.c
index 1265b70..ef5c973 100644
--- a/testsuite/libdejagnu/unit-c.c
+++ b/testsuite/libdejagnu/unit-c.c
@@ -47,6 +47,8 @@ main(int argc, char ** argv)
else if (!strcmp("unresolved", argv[i])) unresolved("test");
else if (!strcmp("unsupported", argv[i])) unsupported("test");
else if (!strcmp("note", argv[i])) note("test");
+ else if (!strcmp("error", argv[i])) DG_error("test");
+ else if (!strcmp("warning", argv[i])) DG_warning("test");
else {
fprintf(stderr, "%s: unknown test `%s'\n", argv[0], argv[i]);
return 2;
diff --git a/testsuite/libdejagnu/unit-ccxxmix.cxx b/testsuite/libdejagnu/unit-ccxxmix.cxx
index a57b073..5116f36 100644
--- a/testsuite/libdejagnu/unit-ccxxmix.cxx
+++ b/testsuite/libdejagnu/unit-ccxxmix.cxx
@@ -52,6 +52,8 @@ main(int argc, char ** argv)
else if (!std::strcmp("unresolved", argv[i])) DGT.unresolved("test");
else if (!std::strcmp("unsupported", argv[i])) DGT.unsupported("test");
else if (!std::strcmp("note", argv[i])) DGT.note("test");
+ else if (!std::strcmp("error", argv[i])) DGT.error("test");
+ else if (!std::strcmp("warning", argv[i])) DGT.warning("test");
else {
std::cerr <<argv[0] <<": unknown test `" <<argv[i] <<"'" <<std::endl;
return 2;
@@ -65,6 +67,8 @@ main(int argc, char ** argv)
else if (!strcmp("unresolved", argv[i])) unresolved("test");
else if (!strcmp("unsupported", argv[i])) unsupported("test");
else if (!strcmp("note", argv[i])) note("test");
+ else if (!strcmp("error", argv[i])) DG_error("test");
+ else if (!strcmp("warning", argv[i])) DG_warning("test");
else {
fprintf(stderr, "%s: unknown test `%s'\n", argv[0], argv[i]);
return 2;
diff --git a/testsuite/libdejagnu/unit-cxx.cxx b/testsuite/libdejagnu/unit-cxx.cxx
index fecf550..aa229d0 100644
--- a/testsuite/libdejagnu/unit-cxx.cxx
+++ b/testsuite/libdejagnu/unit-cxx.cxx
@@ -45,6 +45,8 @@ main(int argc, char ** argv)
else if (!std::strcmp("unresolved", argv[i])) DGT.unresolved("test");
else if (!std::strcmp("unsupported", argv[i])) DGT.unsupported("test");
else if (!std::strcmp("note", argv[i])) DGT.note("test");
+ else if (!std::strcmp("error", argv[i])) DGT.error("test");
+ else if (!std::strcmp("warning", argv[i])) DGT.warning("test");
else {
std::cerr <<argv[0] <<": " <<"unknown test `" <<argv[i] <<"'" <<std::endl;
return 2;