Commit d79e7059 authored by unknown's avatar unknown

negative lists in dbug (-#-d,info => everything but "info").

unit tests for dbug


dbug/Makefile.am:
  unit tests for dbug
dbug/dbug.c:
  negative lists (-#-d,info => everything but "info")
include/my_dbug.h:
  negative lists (-#-d,info => everything but "info")
unittest/Makefile.am:
  unit tests for dbug
dbug/tests-t.pl:
  unit tests for dbug
dbug/tests.c:
  unit tests for dbug
parent 74efae60
......@@ -23,19 +23,20 @@ libdbug_a_SOURCES = dbug.c sanity.c
EXTRA_DIST = CMakeLists.txt example1.c example2.c example3.c \
user.r monty.doc dbug_add_tags.pl \
my_main.c main.c factorial.c dbug_analyze.c \
CMakeLists.txt
CMakeLists.txt tests.c tests-t.pl
NROFF_INC = example1.r example2.r example3.r main.r \
factorial.r output1.r output2.r output3.r \
output4.r output5.r
CLEANFILES = $(NROFF_INC) user.t user.ps
CLEANFILES = $(NROFF_INC) user.t user.ps tests-t
# Must be linked with libs that are not compiled yet
noinst_PROGRAMS = factorial dbug_analyze
noinst_PROGRAMS = factorial dbug_analyze tests
factorial_SOURCES = my_main.c factorial.c
tests_SOURCES = tests.c
dbug_analyze_SOURCES = dbug_analyze.c
all: user.t user.ps
all: user.t user.ps tests-t
user.t: user.r $(NROFF_INC)
-nroff -mm user.r > $@
......@@ -61,5 +62,9 @@ output5.r: factorial
@RM@ -f $@
@SED@ -e 's!\\!\\\\!g' $< > $@
# a hack to have executable in builddir, not in srcdir
tests-t: tests-t.pl
cp $(srcdir)/tests-t.pl $(builddir)/tests-t
# Don't update the files from bitkeeper
%::SCCS/s.%
This diff is collapsed.
#!/usr/bin/perl
#
# A driver program to test DBUG features - runs tests (shell commands)
# from the end of file to invoke tests.c, which does the real dbug work.
#
$exe=$0;
die unless $exe =~ s/(tests)-t(\.exe)?$/$1$2 /;
# load tests
@tests=();
while (<DATA>) {
if (/^% tests /) {
push @tests, [ $' ]
} else {
push @{$tests[$#tests]}, $_
}
}
# require/import instead of use - we know the plan only when tests are loaded
require Test::More;
import Test::More tests => scalar(@tests);
for (@tests) {
$t=$exe . shift @$_;
chomp($t);
open F, '-|', $t or die "open($t|): $!";
local $";
$out=join($", <F>); close(F);
# special cases are handled here:
$out =~ s/Memory: 0x[0-9A-Fa-f]+/Memory: 0x####/g if $t =~ /dump/;
# compare ("\n" at the beginning makes better output in case of errors)
is("\n$out","\n@$_", $t);
}
__DATA__
% tests -#d
func2: info: s=ok
func2: info: s=ok
=> execute
=> evaluate: ON
=> evaluate_if: OFF
main: explain: dbug explained: d
% tests -#d,ret3
=> evaluate: OFF
=> evaluate_if: OFF
% tests -#d:-d,ret3
func2: info: s=ko
func2: info: s=ko
=> execute
=> evaluate: ON
=> evaluate_if: OFF
main: explain: dbug explained: d:-d,ret3
% tests -#t:-d,ret3
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| <func2
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#t:d,info:-d,ret3
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | | info: s=ko
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| | info: s=ko
| <func2
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#t:d,info:-d,ret3:-f,func2
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#t:d,info:-d,ret3:-f,func2 d,evaluate
=> evaluate: ON
=> evaluate_if: OFF
% tests -#t:d,info:-d,ret3:-f,func2 d,evaluate_if
=> evaluate: OFF
=> evaluate_if: ON
% tests -#t:d:-d,ret3:-f,func2 d,evaluate_if
=> evaluate: OFF
=> evaluate_if: ON
% tests -#t:d:-d,ret3:-f,func2 +d,evaluate_if
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
=> evaluate: OFF
=> evaluate_if: ON
<main
% tests -#t:d:-d,ret3:-f,func2
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
=> execute
=> evaluate: ON
=> evaluate_if: OFF
| explain: dbug explained: d:-d,ret3:f:-f,func2:t
<main
% tests -#t:d:-d,ret3:f:-f,func2 -#+d,dump
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
| dump: Memory: 0x#### Bytes: (27)
64 2C 64 75 6D 70 3A 2D 64 2C 72 65 74 33 3A 66 3A 2D 66 2C 66 75 6E 63 32 3A
74
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#t:d:-d,ret3:f:-f,func2 +d,dump
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
| dump: Memory: 0x#### Bytes: (27)
64 2C 64 75 6D 70 3A 2D 64 2C 72 65 74 33 3A 66 3A 2D 66 2C 66 75 6E 63 32 3A
74
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#t:d:-d,ret3:f:-f,func2:+d,dump
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
| dump: Memory: 0x#### Bytes: (27)
64 2C 64 75 6D 70 3A 2D 64 2C 72 65 74 33 3A 66 3A 2D 66 2C 66 75 6E 63 32 3A
74
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#t:d:-d,ret3:f:-f,func2 +d,dump,explain
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
| dump: Memory: 0x#### Bytes: (35)
64 2C 64 75 6D 70 2C 65 78 70 6C 61 69 6E 3A 2D 64 2C 72 65 74 33 3A 66 3A 2D
66 2C 66 75 6E 63 32 3A 74
=> evaluate: OFF
=> evaluate_if: OFF
| explain: dbug explained: d,dump,explain:-d,ret3:f:-f,func2:t
<main
% tests -#t:d:-d,ret3:f:-f,func2 +d,dump,explain:P
dbug: >main
dbug-tests: | >func1
dbug-tests: | | | >func3
dbug-tests: | | | <func3
dbug-tests: | <func1
dbug-tests: | | >func3
dbug-tests: | | <func3
dbug-tests: | dump: Memory: 0x#### Bytes: (37)
64 2C 64 75 6D 70 2C 65 78 70 6C 61 69 6E 3A 2D 64 2C 72 65 74 33 3A 66 3A 2D
66 2C 66 75 6E 63 32 3A 50 3A 74
=> evaluate: OFF
=> evaluate_if: OFF
dbug-tests: | explain: dbug explained: d,dump,explain:-d,ret3:f:-f,func2:P:t
dbug-tests: <main
% tests -#t:d:-d,ret3:f:-f,func2 +d,dump,explain:P:F
dbug: tests.c: >main
dbug-tests: tests.c: | >func1
dbug-tests: tests.c: | | | >func3
dbug-tests: tests.c: | | | <func3
dbug-tests: tests.c: | <func1
dbug-tests: tests.c: | | >func3
dbug-tests: tests.c: | | <func3
dbug-tests: tests.c: | dump: Memory: 0x#### Bytes: (39)
64 2C 64 75 6D 70 2C 65 78 70 6C 61 69 6E 3A 2D 64 2C 72 65 74 33 3A 66 3A 2D
66 2C 66 75 6E 63 32 3A 46 3A 50 3A 74
=> evaluate: OFF
=> evaluate_if: OFF
dbug-tests: tests.c: | explain: dbug explained: d,dump,explain:-d,ret3:f:-f,func2:F:P:t
dbug-tests: tests.c: <main
% tests -#t:d:-d,ret3:f:-f,func2
>main
| >func1
| | | >func3
| | | <func3
| <func1
| | >func3
| | <func3
=> execute
=> evaluate: ON
=> evaluate_if: OFF
| explain: dbug explained: d:-d,ret3:f:-f,func2:t
<main
% tests -#t:d:-d,ret3
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | | info: s=ko
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| | info: s=ko
| <func2
=> execute
=> evaluate: ON
=> evaluate_if: OFF
| explain: dbug explained: d:-d,ret3:t
<main
% tests -#t:d,info:-d,ret3:d,push
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | | info: s=ko
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| | info: s=ko
| <func2
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#d,info:-d,ret3:d,push
func2: info: s=ko
func2: info: s=ko
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#d,info:-d,ret3:d,push,explain
func2: info: s=ko
func2: info: s=ko
=> evaluate: OFF
=> evaluate_if: OFF
| explain: dbug explained: d,info,push,explain:-d,ret3:t
<main
% tests -#d,info:-d,ret3:d,explain
func2: info: s=ko
func2: info: s=ko
=> evaluate: OFF
=> evaluate_if: OFF
main: explain: dbug explained: d,info,explain:-d,ret3
% tests -#d,info:-d,ret3:d,explain,pop
func2: info: s=ko
func2: info: s=ko
=> evaluate: OFF
=> evaluate_if: OFF
% tests -#d,info:-d,ret3:d,explain,pop t
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| <func2
=> evaluate: OFF
=> evaluate_if: OFF
<main
% tests -#d,info:-d,ret3:d,explain,pop +t
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | | info: s=ko
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| | info: s=ko
| <func2
=> evaluate: OFF
=> evaluate_if: OFF
main: explain: dbug explained: d,info,explain,pop:-d,ret3
% tests -#d,info:-d,ret3:d,explain,set
func2: info: s=ko
func2: info: s=ko
=> evaluate: OFF
=> evaluate_if: OFF
tests.c: main: explain: dbug explained: d,info,explain,set:-d,ret3:F
% tests -#d,info:-d,ret3:d,explain,set:t
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | | info: s=ko
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| | info: s=ko
| <func2
=> evaluate: OFF
=> evaluate_if: OFF
tests.c: | explain: dbug explained: d,info,explain,set:-d,ret3:F:t
tests.c: <main
% tests t -#d,info:-d,ret3:d,explain,set:t
>main
| >func1
| | >func2
| | | >func3
| | | <func3
| | | info: s=ko
| | <func2
| <func1
| >func2
| | >func3
| | <func3
| | info: s=ko
| <func2
=> evaluate: OFF
=> evaluate_if: OFF
tests.c: | explain: dbug explained: d,info,explain,set:-d,ret3:F:t
tests.c: <main
% tests t -#d,info:-d,ret3:d,explain,set,pop
func2: info: s=ko
func2: info: s=ko
=> evaluate: OFF
=> evaluate_if: OFF
<main
/*
A program to test DBUG features. Used by tests-t.pl
*/
#ifdef DBUG_OFF /* We are testing dbug */
#undef DBUG_OFF
#endif
#include <my_global.h> /* This includes dbug.h */
#include <my_pthread.h>
#include <string.h>
const char *func3()
{
DBUG_ENTER("func3");
DBUG_RETURN(DBUG_EVALUATE("ret3", "ok", "ko"));
}
void func2()
{
const char *s;
DBUG_ENTER("func2");
s=func3();
DBUG_PRINT("info", ("s=%s", s));
DBUG_VOID_RETURN;
}
int func1()
{
DBUG_ENTER("func1");
func2();
DBUG_RETURN(10);
}
int main (int argc, char *argv[])
{
int i;
#if defined(HAVE_PTHREAD_INIT) && defined(THREAD)
pthread_init(); /* Must be called before DBUG_ENTER */
#endif
#ifdef THREAD
my_thread_global_init();
#endif
dup2(1, 2);
for (i = 1; i < argc; i++)
DBUG_PUSH (argv[i]);
{
DBUG_ENTER ("main");
DBUG_PROCESS ("dbug-tests");
func1();
func2();
DBUG_EXECUTE_IF("dump",
{
char s[1000];
DBUG_EXPLAIN(s, sizeof(s)-1);
DBUG_DUMP("dump", (uchar*)s, strlen(s));
});
DBUG_EXECUTE_IF("push", DBUG_PUSH("+t"); );
DBUG_EXECUTE("execute", fprintf(DBUG_FILE, "=> execute\n"); );
DBUG_EXECUTE_IF("set", DBUG_SET("+F"); );
fprintf(DBUG_FILE, "=> evaluate: %s\n",
DBUG_EVALUATE("evaluate", "ON", "OFF"));
fprintf(DBUG_FILE, "=> evaluate_if: %s\n",
DBUG_EVALUATE_IF("evaluate_if", "ON", "OFF"));
DBUG_EXECUTE_IF("pop", DBUG_POP(); );
{
char s[1000];
DBUG_EXPLAIN(s, sizeof(s)-1);
DBUG_PRINT("explain", ("dbug explained: %s", s));
}
DBUG_RETURN (0);
}
}
......@@ -22,8 +22,7 @@ extern "C" {
#if !defined(DBUG_OFF) && !defined(_lint)
struct _db_code_state_;
extern my_bool _dbug_on_;
extern my_bool _db_keyword_(struct _db_code_state_ *cs, const char *keyword);
extern my_bool _db_strict_keyword_(const char *keyword);
extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
extern int _db_explain_init_(char *buf, size_t len);
extern void _db_setjmp_(void);
......@@ -58,13 +57,13 @@ extern void _db_force_flush();
#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
#define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
#define DBUG_EXECUTE(keyword,a1) \
do {if (_db_keyword_(0, (keyword))) { a1 }} while(0)
do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0)
#define DBUG_EXECUTE_IF(keyword,a1) \
do {if (_db_strict_keyword_ (keyword)) { a1 } } while(0)
do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0)
#define DBUG_EVALUATE(keyword,a1,a2) \
(_db_keyword_(0,(keyword)) ? (a1) : (a2))
(_db_keyword_(0,(keyword), 0) ? (a1) : (a2))
#define DBUG_EVALUATE_IF(keyword,a1,a2) \
(_db_strict_keyword_((keyword)) ? (a1) : (a2))
(_db_keyword_(0,(keyword), 1) ? (a1) : (a2))
#define DBUG_PRINT(keyword,arglist) \
do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0)
#define DBUG_PUSH(a1) _db_push_ (a1)
......
......@@ -18,7 +18,7 @@ SUBDIRS = mytap mysys examples
EXTRA_DIST = unit.pl
CLEANFILES = unit
unittests = mytap mysys @mysql_se_unittest_dirs@ @mysql_pg_unittest_dirs@
unittests = mytap mysys @mysql_se_unittest_dirs@ @mysql_pg_unittest_dirs@ ../dbug
test:
perl unit.pl run $(unittests)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment