Am Sun, 8 Jan 2023 09:37:03 -0500
schrieb Scott Kostyshak <skost...@lyx.org>:

> On Sun, Jan 08, 2023 at 09:30:43AM +0100, Kornel Benko wrote:
> > Am Sun, 8 Jan 2023 00:59:34 +0100
> > schrieb Thibaut Cuvelier <dourou...@gmail.com>:
> >   
> > > On Sat, 7 Jan 2023 at 17:10, Kornel Benko <kor...@lyx.org> wrote:
> > >   
> > > > Am Sat, 7 Jan 2023 16:26:03 +0100
> > > > schrieb Thibaut Cuvelier <dourou...@gmail.com>:
> > > >  
> > > > > > After your recent changes, the number of errors decreased :)
> > > > > >
> > > > > > I got now (for Tufte_Book.xhtml)
> > > > > >         Error: Bad value "content-type" for attribute "http-equiv" 
> > > > > > on  
> > > > element "meta".  
> > > > > >         From line 5, column 1 to line 5, column 68 in resource
> > > > > >  
> > > > file:/usr9/BUILD/Mint21/BuildLyxGitQt5.15.3local-gcc12.1.0/autotests/out-home/AbC_wGZLha/examples/es/Books/Tufte_Book.xhtml
> > > >  
> > > > > >         Document checking completed.  
> > > > > >         > Found 3 validation errors!  
> > > > > >  
> > > > > This one should be fixed at a5c6215e. I still get two warnings with 
> > > > > the  
> > > > latest output,  
> > > > > but they cannot be fixed unless we decide we do not generate 
> > > > > XML-valid  
> > > > HTML at all  
> > > > > (which might be very disruptive for our users).
> > > > >  
> > > >
> > > > Not here. The error is the same as before.
> > > >         Error: Bad value "content-type" for attribute "http-equiv" on
> > > > element "meta".
> > > > Also the test export/mathmacros/testcases_basic_xhtml produces  plenty 
> > > > of
> > > >         Error: Text not allowed in element "mstyle" in this context
> > > >  
> > > 
> > > That's strange, because all 178 documents (including Tufte_book, but not
> > > mathmacros/testcases_basic) do not produce a single validation error on my
> > > machine: generating the XHTML for Tufte_Book and validating it manually (
> > > https://validator.nu/, it's advertised as the same software) doesn't yield
> > > any error. However, testcases_basic is not included in the list of tests I
> > > run. I'm attaching the log to check for differences.
> > > 
> > > For export/mathmacros/testcases_basic_xhtml, it's a bug in the MathML
> > > implementation, the mstyle tag should be an mtext (according to what the
> > > spec and MathType say: mstyle was just for text, but is not really useful
> > > anymore; mtext can contain raw text). It should be fixed at edcaad24; I'm
> > > working on a related validation error (triggered in the same document with
> > > this patch).  
> > 
> > There is no attachment in your mail.
> > 
> > Running the full ctest on the xhtml
> >  $ ctest -R '_xhtml$' -j24
> > gives here
> >  0% tests passed, 421 tests failed out of 421
> > .
> > Moreover, there are now 16 assertions while exporting.
> > autotests/export/docbook/Linguistics.lyx
> > doc/UserGuide.lyx
> > doc/ar/UserGuide.lyx
> > doc/ja/UserGuide.lyx
> > doc/ru/UserGuide.lyx
> > examples/Modules/Linguistics.lyx
> > examples/de/Modules/Linguistics.lyx
> > examples/es/Modules/Linguistics.lyx
> > examples/fr/Modules/Linguistics.lyx
> > examples/ja/Modules/Linguistics.lyx
> > doc/Math.lyx
> > doc/es/Math.lyx
> > doc/de/Math.lyx
> > doc/fr/Math.lyx
> > doc/ru/Math.lyx
> > doc/ja/Math.lyx
> > 
> > The assertion in Linguistics.lyx is triggered only if lyx is compiled with 
> > for
> > debugging. "support/lassert.cpp (52): ASSERTION ucs4[i] < 0x80 VIOLATED IN
> >  /usr2/src/lyx/lyx-git/src/support/docstring.cpp:65
> > 
> > Should I provide you with my ctest-changes? I feel unconfortable to commit 
> > something
> > producing errors while running ctest. OTOH, errors should be corrected.
> > 
> > Scott, what do you think?  
> 
> Thanks to you and Thibaut for working through this. I don't think we
> should commit until the test results are clean.
> 
> If it would help, I'm happy to test a patch and report back the results
> on my side.
> 
> Scott

OK, here they are.

One patch and a new file (development/autotests/simplehtml_validity.py)

        Kornel
diff --git a/development/autotests/ExportTests.cmake b/development/autotests/ExportTests.cmake
index 60d813b48d..e0b31ff953 100644
--- a/development/autotests/ExportTests.cmake
+++ b/development/autotests/ExportTests.cmake
@@ -360,10 +360,11 @@ foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/ta
           -DLYX_FORMAT_NUM=${_lyx_format_num}
           -Dfile=${f}
           -Dinverted=${inverted}
           -DTOP_SRC_DIR=${TOP_SRC_DIR}
           -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
+          -DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}
           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
         setmarkedtestlabel(${TestName} ${mytestlabel})
       endif()
     endforeach()
     if(LYX_PYTHON_EXECUTABLE)
@@ -458,15 +459,15 @@ foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/ta
           else()
             set(mytestlabel ${testlabel} ${extraLabels})
           endif()
           string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
           maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
-	  if (format MATCHES "docbook5")
-	    set(f_extension "xml")
-	  else()
-	    set(f_extension ${format})
-	  endif()
+          if (format MATCHES "docbook5")
+            set(f_extension "xml")
+          else()
+            set(f_extension ${format})
+          endif()
           if(TestName)
             add_test(NAME ${TestName}
               WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
               COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
               -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
@@ -481,10 +482,11 @@ foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/ta
               "-DIgnoreErrorMessage=${missingLabels}"
               -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
               -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
               -DJAVA_EXECUTABLE=${jingjava}
               -DENCODING=${_enc2}
+              -DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}
               -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
             setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports
           endif()
         endforeach()
       endforeach()
diff --git a/development/autotests/export.cmake b/development/autotests/export.cmake
index 43d6df8166..3027526a78 100755
--- a/development/autotests/export.cmake
+++ b/development/autotests/export.cmake
@@ -24,10 +24,11 @@
 #       -Dfile=xxx \
 #       -Dinverted=[01] \
 #       -DTOP_SRC_DIR=${TOP_SRC_DIR} \
 #       -DIgnoreErrorMessage=(ON/OFF) \
 #       -DPERL_EXECUTABLE=${PERL_EXECUTABLE} \
+#       -DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE} \
 #       -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE} \
 #       -DJAVA_EXECUTABLE=${JAVA_EXECUTABLE} \
 #       -DENCODING=xxx \
 #       -P "${TOP_SRC_DIR}/development/autotests/export.cmake"
 #
@@ -55,10 +56,11 @@ endif()
 # filenames
 get_filename_component(updir_ "${LYX_ROOT}" DIRECTORY)
 get_filename_component(updir2_ "${LYX_ROOT}" NAME)
 set(file "${updir2_}/${file}")
 set(LYX_ROOT "${updir_}")
+set(NO_FAILES 0)
 
 if(format MATCHES "dvi|pdf")
   message(STATUS "LYX_TESTS_USERDIR = ${LYX_TESTS_USERDIR}")
   message(STATUS "Converting with perl ${Perl_Script}")
   set(LYX_SOURCE "${TempDir}/${file}_${format}_${_ft}${_enc}.lyx")
@@ -70,10 +72,11 @@ if(format MATCHES "dvi|pdf")
   message(STATUS "Executing ${PERL_EXECUTABLE} \"${Perl_Script}\" \"${LYX_ROOT}/${file}.lyx\" \"${LYX_SOURCE}\" ${format} ${_ft} ${ENCODING} ${LanguageFile}")
   execute_process(COMMAND ${PERL_EXECUTABLE} "${Perl_Script}" "${LYX_ROOT}/${file}.lyx" "${LYX_SOURCE}" ${format} ${_ft} ${ENCODING} ${LanguageFile}
     RESULT_VARIABLE _err)
   string(COMPARE EQUAL  ${_err} 0 _erg)
   if(NOT _erg)
+    set(NO_FAILES 1)
     message(FATAL_ERROR "Export failed while converting")
   endif()
   # We only need "_${ENCODING}" for unicode tests (because multiple encodings
   # are tested with the same format), but doesn't hurt to include for all.
   set(result_file_name ${file}_${_ft}_${ENCODING}.${extension})
@@ -84,12 +87,13 @@ else()
   message(STATUS "Using dest \"${LYX_SOURCE}\"")
   execute_process(COMMAND ${PERL_EXECUTABLE} "${Perl_Script}" "${LYX_ROOT}/${file}.lyx" "${LYX_SOURCE}" ${format} "dontChange" "default" ${LanguageFile}
     RESULT_VARIABLE _err)
   string(COMPARE EQUAL  ${_err} 0 _erg)
   if(NOT _erg)
+    set(NO_FAILES 1)
     message(FATAL_ERROR "Export failed while converting")
-    endif()
+  endif()
   if(extension MATCHES "\\.lyx$")
     # Font-type not relevant for lyx16/lyx2[0123] exports
     set(result_file_base "${TempDir}/${file}")
   else()
     set(result_file_name ${file}.${extension})
@@ -112,16 +116,100 @@ function(get_md5sum msource mresult mreserr)
   set(${mreserr} ${mres_err} PARENT_SCOPE)
 endfunction()
 
 macro(Summary _err _msg)
   if (${_err})
+    MATH(EXPR NO_FAILES "${NO_FAILES}+1")
     list(APPEND _TestResultMessage "Error: ${_msg}")
   else()
     list(APPEND _TestResultMessage "OK: ${_msg}")
   endif()
 endmacro()
 
+macro(check_xhtml_validate xhtml_file)
+  message(STATUS "Calling ${LYX_PYTHON_EXECUTABLE} \"${TOP_SRC_DIR}/development/autotests/simplehtml_validity.py\" \"${TempDir}/${xhtml_file}\"")
+  set(_outputfile "${TempDir}/${xhtml_file}.validate_out")
+  execute_process(
+    COMMAND ${LYX_PYTHON_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/simplehtml_validity.py" "${TempDir}/${xhtml_file}"
+    WORKING_DIRECTORY "${TempDir}"
+    OUTPUT_VARIABLE xmlout
+    ERROR_VARIABLE xmlerr
+    RESULT_VARIABLE _err)
+  file(WRITE "${_outputfile}" ${xmlout})
+  if (_err)
+    Summary(_err "${_err} validating \"${_outputfile}\"")
+    MATH(EXPR NO_FAILES "${NO_FAILES}+1")
+  endif()
+  if (NOT "${xmlout}" STREQUAL "")
+    message(STATUS "${xmlout}")
+    set(_err -1)
+    Summary(_err "Non empty output \"${_outputfile}\" with \"symplehtml_validity.py\"")
+  endif()
+endmacro()
+
+macro(check_xhtml_xmllint xhtml_file)
+  set(xmllint_params --loaddtd --noout)
+  string(REPLACE ";" " " xmllint_params2 " ${xmllint_params}")
+  message(STATUS "Calling: " ${XMLLINT_EXECUTABLE} ${xmllint_params2} " \"${TempDir}/${xhtml_file}\"")
+  set(_outputfile "${TempDir}/${xhtml_file}.sax_out")
+  execute_process(
+    COMMAND ${XMLLINT_EXECUTABLE} ${xmllint_params} "${xhtml_file}"
+    WORKING_DIRECTORY "${TempDir}"
+    OUTPUT_VARIABLE xmlout
+    ERROR_VARIABLE xmlerr
+    RESULT_VARIABLE _err)
+  file(WRITE "${_outputfile}" ${xmlout})
+  Summary(_err "Checking \"${TempDir}/${xhtml_file}\" with ${XMLLINT_EXECUTABLE}")
+  if (NOT _err)
+    # check if parser output contains error messages
+    message(STATUS "Check the output: ${PERL_EXECUTABLE} ${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl")
+    execute_process(
+      COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl" "${_outputfile}"
+      WORKING_DIRECTORY "${TempDir}"
+      OUTPUT_VARIABLE xmlout
+      RESULT_VARIABLE _err)
+    Summary(_err "Parse messages of ${XMLLINT_EXECUTABLE} for errors")
+  else()
+    message(STATUS "Errors from xmllint: ${xmlerr}")
+  endif()
+  if (NOT _err)
+    if (NOT "${xmlout}" STREQUAL "")
+      message(STATUS "${xmlout}")
+      set(_err -1)
+      Summary(_err "Non empty output \"${_outputfile}\" of \"${XMLLINT_EXECUTABLE}\"")
+    endif()
+  endif()
+endmacro()
+
+macro(check_xhtml_xmlparser xhtml_file)
+  message(STATUS "Calling ${PERL_EXECUTABLE} \"${TOP_SRC_DIR}/development/autotests/xmlParser.pl\" \"${xhtml_file}\"")
+  execute_process(
+    COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/xmlParser.pl" "${result_file_name}"
+    WORKING_DIRECTORY "${TempDir}"
+    OUTPUT_VARIABLE parserout
+    ERROR_VARIABLE parsererr
+    RESULT_VARIABLE _err
+  )
+  if (_err)
+    message(STATUS "${parsererr}")
+  endif()
+  Summary(_err "Checking \"${TempDir}/${xhtml_file}\" with xmlParser.pl")
+endmacro()
+
+macro(check_xhtml_jing xhtml_file)
+  message(STATUS "Calling: ${JAVA_EXECUTABLE} -jar \"${TOP_SRC_DIR}/development/tools/jing.jar\" \"https://docbook.org/xml/5.2b09/rng/docbook.rng\"; \"${TempDir}/${xhtml_file}\"")
+  set(_outputfile "${TempDir}/${xhtml_file}.jing_out")
+  execute_process(
+    COMMAND ${JAVA_EXECUTABLE} -jar "${TOP_SRC_DIR}/development/tools/jing.jar" "https://docbook.org/xml/5.2b09/rng/docbook.rng"; "${xhtml_file}"
+    WORKING_DIRECTORY "${TempDir}"
+    OUTPUT_VARIABLE jingout
+    RESULT_VARIABLE _err)
+  file(WRITE "${_outputfile}" ${jingout})
+  message(STATUS "_err = ${_err}, jingout = ${jingout}")
+  Summary(_err "Checking for empty output \"${_outputfile}\" of ${JAVA_EXECUTABLE} -jar \"${TOP_SRC_DIR}/development/tools/jing.jar\"")
+endmacro()
+
 set(ENV{${LYX_USERDIR_VER}} "${LYX_TESTS_USERDIR}")
 set(ENV{LANG} "en_US.UTF-8") # to get all error-messages in english
 set(ENV{LANGUAGE} "US:en")
 #set(ENV{LC_ALL} "C")
 if (extension MATCHES "\\.lyx$")
@@ -232,83 +320,35 @@ else()
       set(_err -1)
       Summary(_err "Expected result file \"${TempDir}/${result_file_name}\" does not exists")
     else()
       message(STATUS "Expected result file \"${TempDir}/${result_file_name}\" exists")
       if (extension MATCHES "^x(ht)?ml$")
-        if (format MATCHES "xhtml")
-          set(xmllint_params --loaddtd --noout)
-          set(executable_ ${XMLLINT_EXECUTABLE})
-        else()
-          set(xmllint_params)
-          set(executable_ ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/filterXml4Sax.pl")
+        if (NOT format MATCHES "xhtml")
           # Check with perl xml-parser
           # needs XML::Parser module
-          message(STATUS "Calling ${PERL_EXECUTABLE} \"${TOP_SRC_DIR}/development/autotests/xmlParser.pl\" \"${result_file_name}\"")
-          execute_process(
-            COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/xmlParser.pl" "${result_file_name}"
-	    WORKING_DIRECTORY "${TempDir}"
-            OUTPUT_VARIABLE parserout
-            ERROR_VARIABLE parsererr
-            RESULT_VARIABLE _err
-          )
-          if (_err)
-            message(STATUS "${parsererr}")
+          check_xhtml_xmlparser(${result_file_name})
+        endif()
+        if (JAVA_EXECUTABLE)
+          if (format MATCHES "docbook5")
+            # check with jing
+            check_xhtml_jing(${result_file_name})
+          else()
+            check_xhtml_validate(${result_file_name})
           endif()
-          Summary(_err "Checking \"${TempDir}/${result_file_name}\" with xmlParser.pl")
         endif()
         if (XMLLINT_EXECUTABLE)
-          string(REPLACE ";" " " xmllint_params2 " ${xmllint_params}")
-          message(STATUS "Calling: " ${executable_} ${xmllint_params2} " ${WORKDIR}/${result_file_name}")
-          # check the created xhtml file
-          execute_process(
-            COMMAND ${executable_} ${xmllint_params}  "${result_file_name}"
-	    WORKING_DIRECTORY "${TempDir}"
-            OUTPUT_VARIABLE xmlout
-            ERROR_VARIABLE xmlerr
-            RESULT_VARIABLE _err)
-          file(WRITE "${TempDir}/${result_file_name}.sax_out" ${xmlout})
-          Summary(_err "Checking \"${TempDir}/${result_file_name}\" with ${XMLLINT_EXECUTABLE}")
-          if (NOT _err)
-            # check if parser output contains error messages
-            message(STATUS "Check the output: ${PERL_EXECUTABLE} ${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl")
-            execute_process(
-              COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl" "${result_file_name}.sax_out"
-	      WORKING_DIRECTORY "${TempDir}"
-              OUTPUT_VARIABLE xmlout
-              RESULT_VARIABLE _err)
-            Summary(_err "Parse messages of ${XMLLINT_EXECUTABLE} for errors")
-          else()
-            message(STATUS "Errors from xmllint: ${xmlerr}")
-          endif()
-          if (NOT _err)
-            if (NOT "${xmlout}" STREQUAL "")
-              message(STATUS "${xmlout}")
-              set(_err -1)
-              Summary(_err "Non empty output of \"${XMLLINT_EXECUTABLE}\"")
-            endif()
-          endif()
-        endif()
-        if (NOT _err AND format MATCHES "docbook5" AND JAVA_EXECUTABLE)
-          # check with jing
-          message(STATUS "Calling: ${JAVA_EXECUTABLE} -jar \"${TOP_SRC_DIR}/development/tools/jing.jar\" https://docbook.org/xml/5.2b09/rng/docbook.rng \"${WORKDIR}/${result_file_name}\"")
-          execute_process(
-            COMMAND ${JAVA_EXECUTABLE} -jar "${TOP_SRC_DIR}/development/tools/jing.jar" "https://docbook.org/xml/5.2b09/rng/docbook.rng"; "${result_file_name}"
-	    WORKING_DIRECTORY "${TempDir}"
-            OUTPUT_VARIABLE jingout
-            RESULT_VARIABLE _err)
-          message(STATUS "_err = ${_err}, jingout = ${jingout}")
-          Summary(_err "Checking for empty output of ${JAVA_EXECUTABLE} -jar \"${TOP_SRC_DIR}/development/tools/jing.jar\"")
+          check_xhtml_xmllint(${result_file_name})
         endif()
       endif()
     endif()
   endif()
 endif()
 
 if(inverted)
-  string(COMPARE EQUAL  ${_err} 0 _erg)
+  string(COMPARE EQUAL  ${NO_FAILES} 0 _erg)
 else()
-  string(COMPARE NOTEQUAL  ${_err} 0 _erg)
+  string(COMPARE NOTEQUAL  ${NO_FAILES} 0 _erg)
 endif()
 
 if ($ENV{LYX_DEBUG_LATEX})
   # Do not remove temporary files if one wants to examine them
   # for example if setting the env-var LYX_DEBUG_LATEX
# Stricter version of the export tests: validate the XHTML code produced by
# LyX' lyxhtml output as HTML5. It also validates the CSS and MathML parts.
# Validation errors usually are mistakes in the generator.
#
# Call:
#     python simplehtml_validity.py PATH_TO_HTML5_SOURCE
#
# Written with Python 3.8.8.
# Requirements:
# - Python package: html5validator: at least v0.4.2
# - Java runtime engine (JRE): at least v8 (depending on html5validator)
# Run:
#     pip install html5validator>=0.4.2

import collections
import glob
import sys
import tempfile
import os

import html5validator


if len(sys.argv) != 2:
    print('Expecting one argument, the path to the LyX-create xhtml file')
    sys.exit(-1)
if not os.path.exists(sys.argv[1]):
    print('The given path does not point to an existing file')
    sys.exit(-1)


xhtml_file_name = sys.argv[1]
xhtml_list = [xhtml_file_name]

validator = html5validator.Validator(format='text')
error_count = validator.validate(xhtml_list)

n_invalid = 0
n_valid = 0
if error_count == 0:
    n_valid += 1
    print(f'> Found no validation error!')
    sys.exit(0)
else:
    n_invalid += 1
    print(f'> Found {error_count} validation error{"" if error_count == 1 else "s"}!')
    sys.exit(-2)

if n_invalid == 0:
    print("That's excellent! Give yourself a pat on the back!")
    sys.exit(0)
else:
    sys.exit(-3)

Attachment: pgp25DTdun20Q.pgp
Description: Digitale Signatur von OpenPGP

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to