Skip to content

Commit

Permalink
Add support for reporting errors and warnings in dejagnu.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Bachmeyer committed Dec 21, 2022
1 parent 4d82991 commit d807904
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
2022-12-20 Jacob Bachmeyer <[email protected]>

* 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.
Expand Down
38 changes: 38 additions & 0 deletions dejagnu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 33 additions & 1 deletion doc/dejagnu.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions testsuite/libdejagnu/harness.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -134,11 +136,19 @@ 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}
}
}

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 changes: 2 additions & 0 deletions testsuite/libdejagnu/unit-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions testsuite/libdejagnu/unit-ccxxmix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions testsuite/libdejagnu/unit-cxx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d807904

Please sign in to comment.