Commit bb5ababa authored by Daniel Veillard's avatar Daniel Veillard
Browse files

more cleanup in make tests more work in the transition to the new error

* Makefile.am: more cleanup in make tests
* error.c valid.c parser.c include/libxml/xmlerror.h: more work
  in the transition to the new error reporting strategy.
* python/tests/reader2.py  result/VC/* result/valid/*:
  few changes in the strings generated by the validation output
Daniel
parent 2b8c4a15
Sat Oct 4 00:18:29 CEST 2003 Daniel Veillard <daniel@veillard.com>
* Makefile.am: more cleanup in make tests
* error.c valid.c parser.c include/libxml/xmlerror.h: more work
in the transition to the new error reporting strategy.
* python/tests/reader2.py result/VC/* result/valid/*:
few changes in the strings generated by the validation output
Fri Oct 3 00:19:02 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
* Makefile.am: changed 'make tests' to use a concise output,
......
......@@ -514,8 +514,9 @@ SVGtests : xmllint$(EXEEXT)
Threadtests : testThreads$(EXEEXT)
@echo "## Threaded regression tests"
-($(CHECKER) $(top_builddir)/testThreads ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";)
-@($(CHECKER) $(top_builddir)/testThreads ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0"; \
exit 0)
Readertests : xmllint$(EXEEXT)
@(echo > .memdump)
......@@ -786,8 +787,6 @@ Relaxtests: xmllint$(EXEEXT)
fi ; fi ; \
done; done)
@echo "## Relax-NG streaming regression tests"
@echo "## Some error messages are different than non-streaming"
@echo "## and generate small diffs"
-@(for i in $(srcdir)/test/relaxng/*.rng ; do \
name=`basename $$i | sed 's+\.rng++'`; \
for j in $(srcdir)/test/relaxng/"$$name"_*.xml ; do \
......@@ -804,11 +803,11 @@ Relaxtests: xmllint$(EXEEXT)
log=`$(CHECKER) $(top_builddir)/xmllint$(EXEEXT) --noout --stream --relaxng $$i $$j \
> res.$$name 2> err.$$name;\
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/relaxng/"$$name"_"$$xno" \
res.$$name;\
diff $(srcdir)/result/relaxng/"$$name"_"$$xno".err \
err.$$name | grep -v "error detected at";\
grep Unimplemented err.$$name`; \
diff $(srcdir)/result/relaxng/"$$name"_"$$xno" res.$$name;\
if [ "$$name" != "tutor10_1" -a "$$name" != "tutor10_2" -a "$$name" != "tutor3_2" ] ; then \
diff $(srcdir)/result/relaxng/"$$name"_"$$xno".err \
err.$$name | grep -v "error detected at";\
fi ; grep Unimplemented err.$$name`; \
if [ -n "$$log" ] ; then echo $$name result ; echo $$log ; fi ; \
rm res.$$name err.$$name ; \
fi ; fi ; \
......
......@@ -208,6 +208,7 @@ xmlParserPrintFileContext(xmlParserInputPtr input) {
/**
* xmlReportError:
* @err: the error
* @ctx: the parser context or NULL
* @str: the formatted error message
*
......@@ -215,7 +216,8 @@ xmlParserPrintFileContext(xmlParserInputPtr input) {
* routines.
*/
static void
xmlReportError(xmlParserCtxtPtr ctxt, const char *str) {
xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str)
{
char *file = NULL;
int line = 0;
int code = -1;
......@@ -226,33 +228,41 @@ xmlReportError(xmlParserCtxtPtr ctxt, const char *str) {
xmlParserInputPtr cur = NULL;
void *data;
if (ctxt == NULL) return;
if (err == NULL)
return;
channel = xmlGenericError;
data = xmlGenericErrorContext;
file = ctxt->lastError.file;
line = ctxt->lastError.line;
code = ctxt->lastError.code;
domain = ctxt->lastError.domain;
level = ctxt->lastError.level;
file = err->file;
line = err->line;
code = err->code;
domain = err->domain;
level = err->level;
if (code == XML_ERR_OK)
return;
/*
* Maintain the compatibility with the legacy error handling
*/
input = ctxt->input;
if ((input != NULL) && (input->filename == NULL) &&
(ctxt->inputNr > 1)) {
cur = input;
input = ctxt->inputTab[ctxt->inputNr - 2];
}
if (input != NULL) {
if (input->filename)
channel(data, "%s:%d: ", input->filename, input->line);
else
channel(data, "Entity: line %d: ", input->line);
if (ctxt != NULL) {
input = ctxt->input;
if ((input != NULL) && (input->filename == NULL) &&
(ctxt->inputNr > 1)) {
cur = input;
input = ctxt->inputTab[ctxt->inputNr - 2];
}
if (input != NULL) {
if (input->filename)
channel(data, "%s:%d: ", input->filename, input->line);
else
channel(data, "Entity: line %d: ", input->line);
}
} else {
if (file != NULL)
channel(data, "%s:%d: ", file, line);
else
channel(data, "Entity: line %d: ", line);
}
if (code == XML_ERR_OK)
return;
......@@ -313,16 +323,16 @@ xmlReportError(xmlParserCtxtPtr ctxt, const char *str) {
switch (level) {
case XML_ERR_NONE:
channel(data, ": ");
break;
break;
case XML_ERR_WARNING:
channel(data, "warning : ");
break;
break;
case XML_ERR_ERROR:
channel(data, "error : ");
break;
break;
case XML_ERR_FATAL:
channel(data, "error : ");
break;
break;
}
if (code == XML_ERR_OK)
return;
......@@ -347,7 +357,10 @@ xmlReportError(xmlParserCtxtPtr ctxt, const char *str) {
}
/**
* xmlRaiseError:
* __xmlRaiseError:
* @channel: the callback channel
* @data: the callback data
* @ctx: the parser context or NULL
* @ctx: the parser context or NULL
* @domain: the domain for the error
* @code: the code for the error
......@@ -367,17 +380,18 @@ xmlReportError(xmlParserCtxtPtr ctxt, const char *str) {
* error callback handler
*/
void
xmlRaiseError(void *ctx, int domain, int code, xmlErrorLevel level,
__xmlRaiseError(xmlGenericErrorFunc channel, void *data, void *ctx,
void *nod, int domain, int code, xmlErrorLevel level,
const char *file, int line, const char *str1,
const char *str2, const char *str3, int int1, int int2,
const char *msg, ...)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr node = (xmlNodePtr) nod;
char *str = NULL;
xmlParserInputPtr input = NULL;
xmlErrorPtr to = &xmlLastError;
xmlGenericErrorFunc channel;
void *data;
xmlChar *base = NULL;
if (code == XML_ERR_OK)
return;
......@@ -406,6 +420,15 @@ xmlRaiseError(void *ctx, int domain, int code, xmlErrorLevel level,
}
}
to = &ctxt->lastError;
} else if ((node != NULL) && (file == NULL)) {
int i;
base = xmlNodeGetBase(NULL, node);
for (i = 0;
((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE));
i++)
node = node->parent;
if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
line = (int) node->content;
}
/*
......@@ -418,6 +441,10 @@ xmlRaiseError(void *ctx, int domain, int code, xmlErrorLevel level,
to->level = level;
if (file != NULL)
to->file = (char *) xmlStrdup((const xmlChar *) file);
else if (base != NULL) {
to->file = (char *) base;
file = (char *) base;
}
to->line = line;
if (str1 != NULL)
to->str1 = (char *) xmlStrdup((const xmlChar *) str1);
......@@ -431,13 +458,13 @@ xmlRaiseError(void *ctx, int domain, int code, xmlErrorLevel level,
/*
* Find the callback channel.
*/
if (ctxt != NULL) {
if ((ctxt != NULL) && (channel == NULL)) {
if (level == XML_ERR_WARNING)
channel = ctxt->sax->warning;
else
channel = ctxt->sax->error;
data = ctxt;
} else {
} else if (channel == NULL) {
channel = xmlGenericError;
data = xmlGenericErrorContext;
}
......@@ -448,7 +475,7 @@ xmlRaiseError(void *ctx, int domain, int code, xmlErrorLevel level,
(channel == xmlParserWarning) ||
(channel == xmlParserValidityError) ||
(channel == xmlParserValidityWarning))
xmlReportError(ctxt, str);
xmlReportError(to, ctxt, str);
else
channel(data, "%s", str);
}
......
......@@ -206,10 +206,44 @@ typedef enum {
XML_NS_ERR_ATTRIBUTE_REDEFINED,
XML_ERR_CONDSEC_INVALID_KEYWORD,
XML_ERR_VERSION_MISSING,
XML_DTD_ATTRIBUTE_DEFAULT,
XML_DTD_ATTRIBUTE_REDEFINED,
XML_DTD_ATTRIBUTE_VALUE,
XML_DTD_CONTENT_ERROR,
XML_DTD_CONTENT_MODEL,
XML_DTD_CONTENT_NOT_DETERMINIST,
XML_DTD_DIFFERENT_PREFIX,
XML_DTD_ELEM_DEFAULT_NAMESPACE,
XML_DTD_ELEM_NAMESPACE,
XML_DTD_ELEM_REDEFINED,
XML_DTD_EMPTY_NOTATION,
XML_DTD_ENTITY_TYPE,
XML_DTD_ID_FIXED,
XML_DTD_ID_REDEFINED,
XML_DTD_ID_SUBSET,
XML_DTD_INVALID_CHILD,
XML_DTD_INVALID_DEFAULT,
XML_DTD_LOAD_ERROR,
XML_DTD_MISSING_ATTRIBUTE,
XML_DTD_MIXED_CORRUPT,
XML_DTD_MULTIPLE_ID,
XML_DTD_NO_DOC,
XML_DTD_NO_DTD,
XML_DTD_NO_ELEM_NAME,
XML_DTD_NOTATION_REDEFINED
XML_DTD_NO_PREFIX,
XML_DTD_NO_ROOT,
XML_DTD_NOTATION_REDEFINED,
XML_DTD_NOTATION_VALUE,
XML_DTD_NOT_EMPTY,
XML_DTD_NOT_PCDATA,
XML_DTD_NOT_STANDALONE,
XML_DTD_ROOT_NAME,
XML_DTD_STANDALONE_WHITE_SPACE,
XML_DTD_UNKNOWN_ATTRIBUTE,
XML_DTD_UNKNOWN_ELEM,
XML_DTD_UNKNOWN_ENTITY,
XML_DTD_UNKNOWN_ID,
XML_DTD_UNKNOWN_NOTATION
} xmlParserErrors;
/**
......@@ -277,11 +311,15 @@ XMLPUBFUN int XMLCALL
xmlCopyError (xmlErrorPtr from,
xmlErrorPtr to);
#ifdef IN_LIBXML
/*
* Intended for internal use mostly
* Internal callback reporting routine
*/
XMLPUBFUN void XMLCALL
xmlRaiseError (void *ctx,
XMLPUBFUN void XMLCALL
__xmlRaiseError (xmlGenericErrorFunc channel,
void *data,
void *ctx,
void *node,
int domain,
int code,
xmlErrorLevel level,
......@@ -294,6 +332,7 @@ XMLPUBFUN void XMLCALL
int int2,
const char *msg,
...);
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -128,6 +128,7 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
* *
************************************************************************/
/**
* xmlErrMemory:
* @ctxt: an XML parser context
......@@ -144,13 +145,14 @@ xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
ctxt->disableSAX = 1;
}
if (extra)
xmlRaiseError(ctxt, XML_FROM_PARSER, XML_ERR_NO_MEMORY,
XML_ERR_FATAL, NULL, 0, extra, NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
else
xmlRaiseError(ctxt, XML_FROM_PARSER, XML_ERR_NO_MEMORY,
XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0,
"Memory allocation failed\n");
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
NULL, NULL, 0, 0, "Memory allocation failed\n");
}
/**
......@@ -167,14 +169,16 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix,
{
ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED;
if (prefix == NULL)
xmlRaiseError(ctxt, XML_FROM_PARSER, ctxt->errNo, XML_ERR_FATAL,
NULL, 0, (const char *) localname, NULL, NULL, 0, 0,
"Attribute %s redefined\n", localname);
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
ctxt->errNo, XML_ERR_FATAL, NULL, 0,
(const char *) localname, NULL, NULL, 0, 0,
"Attribute %s redefined\n", localname);
else
xmlRaiseError(ctxt, XML_FROM_PARSER, ctxt->errNo, XML_ERR_FATAL,
NULL, 0, (const char *) prefix,
(const char *) localname, NULL, 0, 0,
"Attribute %s:%s redefined\n", prefix, localname);
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
ctxt->errNo, XML_ERR_FATAL, NULL, 0,
(const char *) prefix, (const char *) localname,
NULL, 0, 0, "Attribute %s:%s redefined\n", prefix,
localname);
ctxt->wellFormed = 0;
if (ctxt->recovery == 0)
ctxt->disableSAX = 1;
......@@ -189,190 +193,193 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix,
* Handle a fatal parser error, i.e. violating Well-Formedness constraints
*/
static void
xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char * info)
xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
{
const char *errmsg;
switch (error) {
case XML_ERR_INVALID_HEX_CHARREF:
errmsg = "CharRef: invalid hexadecimal value\n";
break;
errmsg = "CharRef: invalid hexadecimal value\n";
break;
case XML_ERR_INVALID_DEC_CHARREF:
errmsg = "CharRef: invalid decimal value\n";
break;
errmsg = "CharRef: invalid decimal value\n";
break;
case XML_ERR_INVALID_CHARREF:
errmsg = "CharRef: invalid value\n";
break;
errmsg = "CharRef: invalid value\n";
break;
case XML_ERR_INTERNAL_ERROR:
errmsg = "internal error";
break;
errmsg = "internal error";
break;
case XML_ERR_PEREF_AT_EOF:
errmsg = "PEReference at end of document\n";
break;
errmsg = "PEReference at end of document\n";
break;
case XML_ERR_PEREF_IN_PROLOG:
errmsg = "PEReference in prolog\n";
break;
errmsg = "PEReference in prolog\n";
break;
case XML_ERR_PEREF_IN_EPILOG:
errmsg = "PEReference in epilog\n";
break;
errmsg = "PEReference in epilog\n";
break;
case XML_ERR_PEREF_NO_NAME:
errmsg = "PEReference: no name\n";
break;
errmsg = "PEReference: no name\n";
break;
case XML_ERR_PEREF_SEMICOL_MISSING:
errmsg = "PEReference: expecting ';'\n";
break;
errmsg = "PEReference: expecting ';'\n";
break;
case XML_ERR_ENTITY_LOOP:
errmsg = "Detected an entity reference loop\n";
break;
errmsg = "Detected an entity reference loop\n";
break;
case XML_ERR_ENTITY_NOT_STARTED:
errmsg = "EntityValue: \" or ' expected\n";
break;
errmsg = "EntityValue: \" or ' expected\n";
break;
case XML_ERR_ENTITY_PE_INTERNAL:
errmsg = "PEReferences forbidden in internal subset\n";
break;
errmsg = "PEReferences forbidden in internal subset\n";
break;
case XML_ERR_ENTITY_NOT_FINISHED:
errmsg = "EntityValue: \" or ' expected\n";
break;
errmsg = "EntityValue: \" or ' expected\n";
break;
case XML_ERR_ATTRIBUTE_NOT_STARTED:
errmsg = "AttValue: \" or ' expected\n";
break;
errmsg = "AttValue: \" or ' expected\n";
break;
case XML_ERR_LT_IN_ATTRIBUTE:
errmsg = "Unescaped '<' not allowed in attributes values\n";
break;
errmsg = "Unescaped '<' not allowed in attributes values\n";
break;
case XML_ERR_LITERAL_NOT_STARTED:
errmsg = "SystemLiteral \" or ' expected\n";
break;
errmsg = "SystemLiteral \" or ' expected\n";
break;
case XML_ERR_LITERAL_NOT_FINISHED:
errmsg = "Unfinished System or Public ID \" or ' expected\n";
break;
errmsg = "Unfinished System or Public ID \" or ' expected\n";
break;
case XML_ERR_MISPLACED_CDATA_END:
errmsg = "Sequence ']]>' not allowed in content\n";
break;
errmsg = "Sequence ']]>' not allowed in content\n";
break;
case XML_ERR_URI_REQUIRED:
errmsg = "SYSTEM or PUBLIC, the URI is missing\n";
break;
errmsg = "SYSTEM or PUBLIC, the URI is missing\n";
break;
case XML_ERR_PUBID_REQUIRED:
errmsg = "PUBLIC, the Public Identifier is missing\n";
break;
errmsg = "PUBLIC, the Public Identifier is missing\n";
break;
case XML_ERR_HYPHEN_IN_COMMENT:
errmsg = "Comment must not contain '--' (double-hyphen)\n";
break;
errmsg = "Comment must not contain '--' (double-hyphen)\n";
break;
case XML_ERR_PI_NOT_STARTED:
errmsg = "xmlParsePI : no target name\n";
break;
errmsg = "xmlParsePI : no target name\n";
break;
case XML_ERR_RESERVED_XML_NAME:
errmsg = "Invalid PI name\n";
break;
errmsg = "Invalid PI name\n";
break;
case XML_ERR_NOTATION_NOT_STARTED:
errmsg = "NOTATION: Name expected here\n";
break;
errmsg = "NOTATION: Name expected here\n";
break;
case XML_ERR_NOTATION_NOT_FINISHED:
errmsg = "'>' required to close NOTATION declaration\n";
break;
errmsg = "'>' required to close NOTATION declaration\n";
break;
case XML_ERR_VALUE_REQUIRED:
errmsg = "Entity value required\n";
break;
errmsg = "Entity value required\n";
break;
case XML_ERR_URI_FRAGMENT:
errmsg = "Fragment not allowed";
break;
errmsg = "Fragment not allowed";
break;
case XML_ERR_ATTLIST_NOT_STARTED:
errmsg = "'(' required to start ATTLIST enumeration\n";
break;
errmsg = "'(' required to start ATTLIST enumeration\n";
break;
case XML_ERR_NMTOKEN_REQUIRED:
errmsg = "NmToken expected in ATTLIST enumeration\n";
break;
errmsg = "NmToken expected in ATTLIST enumeration\n";
break;
case XML_ERR_ATTLIST_NOT_FINISHED:
errmsg = "')' required to finish ATTLIST enumeration\n";
break;
errmsg = "')' required to finish ATTLIST enumeration\n";
break;
case XML_ERR_MIXED_NOT_STARTED:
errmsg = "MixedContentDecl : '|' or ')*' expected\n";
break;
errmsg = "MixedContentDecl : '|' or ')*' expected\n";
break;
case XML_ERR_PCDATA_REQUIRED:
errmsg = "MixedContentDecl : '#PCDATA' expected\n";
break;
errmsg = "MixedContentDecl : '#PCDATA' expected\n";
break;
case XML_ERR_ELEMCONTENT_NOT_STARTED:
errmsg = "ContentDecl : Name or '(' expected\n";
break;
errmsg = "ContentDecl : Name or '(' expected\n";
break;
case XML_ERR_ELEMCONTENT_NOT_FINISHED:
errmsg = "ContentDecl : ',' '|' or ')' expected\n";
break;
errmsg = "ContentDecl : ',' '|' or ')' expected\n";
break;
case XML_ERR_PEREF_IN_INT_SUBSET:
errmsg = "PEReference: forbidden within markup decl in internal subset\n";
break;
errmsg =
"PEReference: forbidden within markup decl in internal subset\n";
break;
case XML_ERR_GT_REQUIRED:
errmsg = "expected '>'\n";
break;
errmsg = "expected '>'\n";
break;
case XML_ERR_CONDSEC_INVALID:
errmsg = "XML conditional section '[' expected\n";
break;
errmsg = "XML conditional section '[' expected\n";
break;
case XML_ERR_EXT_SUBSET_NOT_FINISHED:
errmsg = "Content error in the external subset\n";
break;
case XML_ERR_CONDSEC_INVALID_KEYWORD:
errmsg = "conditional section INCLUDE or IGNORE keyword expected\n";
break;
errmsg = "Content error in the external subset\n";
break;
case XML_ERR_CONDSEC_INVALID_KEYWORD:
errmsg =
"conditional section INCLUDE or IGNORE keyword expected\n";
break;
case XML_ERR_CONDSEC_NOT_FINISHED:
errmsg = "XML conditional section not closed\n";
break;
errmsg = "XML conditional section not closed\n";
break;
case XML_ERR_XMLDECL_NOT_STARTED:
errmsg = "Text declaration '<?xml' required\n";
break;
errmsg = "Text declaration '<?xml' required\n";
break;
case XML_ERR_XMLDECL_NOT_FINISHED:
errmsg = "parsing XML declaration: '?>' expected\n";
break;
errmsg = "parsing XML declaration: '?>' expected\n";
break;
case XML_ERR_EXT_ENTITY_STANDALONE:
errmsg = "external parsed entities cannot be standalone\n";
break;
errmsg = "external parsed entities cannot be standalone\n";
break;
case XML_ERR_ENTITYREF_SEMICOL_MISSING:
errmsg = "EntityRef: expecting ';'\n";
break;
errmsg = "EntityRef: expecting ';'\n";
break;
case XML_ERR_DOCTYPE_NOT_FINISHED:
errmsg = "DOCTYPE improperly terminated\n";
break;
errmsg = "DOCTYPE improperly terminated\n";
break;
case XML_ERR_LTSLASH_REQUIRED:
errmsg = "EndTag: '</' not found\n";
break;
errmsg = "EndTag: '</' not found\n";
break;
case XML_ERR_EQUAL_REQUIRED:
errmsg = "expected '='\n";
break;
errmsg = "expected '='\n";
break;
case XML_ERR_STRING_NOT_CLOSED:
errmsg = "String not closed expecting \" or '\n";
break;
errmsg = "String not closed expecting \" or '\n";
break;
case XML_ERR_STRING_NOT_STARTED:
errmsg = "String not started expecting ' or \"\n";
break;
errmsg = "String not started expecting ' or \"\n";
break;
case XML_ERR_ENCODING_NAME:
errmsg = "Invalid XML encoding name\n";
break;
errmsg = "Invalid XML encoding name\n";
break;