Fix and re-enable htmlreport tests (#2310)
* htmlreport/check.sh: Remove check with obsolete file
gui/test/data/xmlfiles/xmlreport_v1.xml has been removed with commit
d95efc44c7
* .travis.yml: Enable htmlreport test again
* cppcheck-htmlreport: Fall back to guessing lexer from file content
If the lexer can not be guessed from the file extension (for example
for *.tpp) then guess the lexer that should be used from the content.
This fixes "ERROR: *" output when running "htmlreport/check.sh"
Also use specific exceptions instead of bare ones.
This commit is contained in:
parent
694d147097
commit
816aa7e211
11
.travis.yml
11
.travis.yml
|
@ -69,12 +69,11 @@ matrix:
|
|||
- make validateXML
|
||||
# Validate rule files
|
||||
- make validateRules
|
||||
# note: trusty on travis has python pygments disabled so disable these tests on travis
|
||||
## check htmlreport stuff
|
||||
# - ./htmlreport/test_htmlreport.py
|
||||
# - cd htmlreport
|
||||
# - ./check.sh
|
||||
# - cd ../
|
||||
# check htmlreport stuff
|
||||
- ./htmlreport/test_htmlreport.py
|
||||
- cd htmlreport
|
||||
- ./check.sh
|
||||
- cd ../
|
||||
# check if DESTDIR works TODO: actually execute this
|
||||
- mkdir install_test
|
||||
- echo $CXXFLAGS
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#!/bin/bash -ex
|
||||
|
||||
|
||||
./cppcheck-htmlreport --file ../gui/test/data/xmlfiles/xmlreport_v1.xml --title "xml1 test" --report-dir . --source-dir ../test/
|
||||
./cppcheck-htmlreport --file ../gui/test/data/xmlfiles/xmlreport_v2.xml --title "xml2 test" --report-dir . --source-dir ../test/
|
||||
echo -e "\n"
|
||||
|
||||
|
|
|
@ -10,8 +10,9 @@ import operator
|
|||
|
||||
from collections import Counter
|
||||
from pygments import highlight
|
||||
from pygments.lexers import guess_lexer_for_filename
|
||||
from pygments.lexers import guess_lexer, guess_lexer_for_filename
|
||||
from pygments.formatters import HtmlFormatter
|
||||
from pygments.util import ClassNotFound
|
||||
from xml.sax import parse as xml_parse
|
||||
from xml.sax import SAXParseException as XmlParseException
|
||||
from xml.sax.handler import ContentHandler as XmlContentHandler
|
||||
|
@ -523,7 +524,10 @@ if __name__ == '__main__':
|
|||
output_file.write(HTML_HEAD_END)
|
||||
try:
|
||||
lexer = guess_lexer_for_filename(source_filename, '')
|
||||
except:
|
||||
except ClassNotFound:
|
||||
try:
|
||||
lexer = guess_lexer(content)
|
||||
except ClassNotFound:
|
||||
sys.stderr.write("ERROR: Couldn't determine lexer for the file' " + source_filename + " '. Won't be able to syntax highlight this file.")
|
||||
output_file.write("\n <tr><td colspan='5'> Could not generated content because pygments failed to retrieve the determine code type.</td></tr>")
|
||||
output_file.write("\n <tr><td colspan='5'> Sorry about this.</td></tr>")
|
||||
|
|
Loading…
Reference in New Issue