1# Copyright 2006-2008 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15# Generate an XQTS test submission from a recent CTest run.
16
17get_filename_component (cwd ${CMAKE_CURRENT_LIST_FILE} PATH)
18if (ZORBA_BUILD_DIR)
19  set (builddir "${ZORBA_BUILD_DIR}")
20else ()
21  set (builddir "${cwd}/../../../../build")
22endif ()
23find_program(zorba NAMES zorba zorba.exe PATHS "${builddir}" "${builddir}/release" PATH_SUFFIXES bin)
24if (NOT zorba)
25  message (FATAL_ERROR "Zorba is required; not found. Specify -DZORBA_BUILD_DIR to point to your build directory if necessary.")
26endif ()
27
28find_program(testdriver_mt NAMES testdriver_mt PATHS "${builddir}" "${builddir}/release" PATH_SUFFIXES test/rbkt)
29if (testdriver_mt)
30  # Use the Test.xml generated by the testdriver_mt
31  set (testfile "${builddir}/Testing/Test.xml")
32endif ()
33
34#it might be that the testdriver_mt exists, but the user has chosen to generate the results with ctest(testdriver) instead of testdriver_mt
35if (NOT EXISTS "${testfile}")
36  # Read most recent CTest tag and find out the corresponding Test.xml
37  file (STRINGS "${builddir}/Testing/TAG" _tag_content)
38  list (GET _tag_content 0 ctest_tag)
39  set (testfile "${builddir}/Testing/${ctest_tag}/Test.xml")
40  # MESSAGE(STATUS "using testresults from: ${testfile}")
41endif ()
42
43if (EXISTS "${testfile}")
44  # Execute Zorba
45  execute_process (COMMAND "${zorba}" --omit-xml-declaration --indent
46                  --query "${cwd}/generate-submission-xqts.xq" --as-files
47                  -e "ctests=${testfile}")
48else()
49  message (FATAL_ERROR "Test.xml was found, please follow each step described in the 'test/rbkt/Scripts/w3c/Readme.txt'.")
50endif ()
51