Browse Source

Add support for reporting errors and warnings in dejagnu.h

master
Jacob Bachmeyer 4 years ago
parent
commit
d807904c11
  1. 12
      ChangeLog
  2. 38
      dejagnu.h
  3. 34
      doc/dejagnu.texi
  4. 10
      testsuite/libdejagnu/harness.exp
  5. 2
      testsuite/libdejagnu/unit-c.c
  6. 4
      testsuite/libdejagnu/unit-ccxxmix.cxx
  7. 2
      testsuite/libdejagnu/unit-cxx.cxx

12
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.

38
dejagnu.h

@ -176,6 +176,34 @@ note (const char* fmt, ...)
funlockfile (stdout);
}
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)
{
@ -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;

34
doc/dejagnu.texi

@ -2644,6 +2644,22 @@ facility that is not available in the testing environment.
@t{@b{unsupported}(@i{msg}, ...);}
@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
@ -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

10
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}
}

2
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;

4
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;

2
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;

Loading…
Cancel
Save