~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Tests/CMakeTests/ExecuteScriptTests.cmake

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This function calls the ${scriptname} file to execute one test case:
 
2
#
 
3
function(execute_one_script_test scriptname testname expected_result)
 
4
  message("execute_one_script_test")
 
5
  message("testname=[${testname}]")
 
6
 
 
7
  execute_process(
 
8
    COMMAND ${CMAKE_COMMAND}
 
9
      -D "dir:STRING=${dir}"
 
10
      -D "testname:STRING=${testname}"
 
11
      -P "${scriptname}"
 
12
    OUTPUT_VARIABLE out
 
13
    ERROR_VARIABLE err
 
14
    RESULT_VARIABLE result
 
15
    OUTPUT_STRIP_TRAILING_WHITESPACE
 
16
    ERROR_STRIP_TRAILING_WHITESPACE
 
17
    )
 
18
 
 
19
  message("out=[${out}]")
 
20
  message("err=[${err}]")
 
21
 
 
22
  if(expected_result STREQUAL "fail")
 
23
    # case expected to fail, result should be non-0...
 
24
    # error if it's 0
 
25
    if("${result}" STREQUAL "0")
 
26
      message(SEND_ERROR "script failed: testname='${testname}' [${result}] actually passed, but expected to fail...")
 
27
    endif()
 
28
  else()
 
29
    # case expected to pass, result should be 0...
 
30
    # error if it's non-0
 
31
    if(NOT "${result}" STREQUAL "0")
 
32
      message(SEND_ERROR "script failed: testname='${testname}' [${result}] actually failed, but expected to pass...")
 
33
   endif()
 
34
  endif()
 
35
 
 
36
  message("")
 
37
endfunction()
 
38
 
 
39
 
 
40
# This function reads the script file and calls execute_one_script_test for
 
41
# each testname case listed in the script. To add new cases, simply edit the
 
42
# script file and add an elseif() clause that matches 'regex' below.
 
43
#
 
44
function(execute_all_script_tests scriptname result)
 
45
  file(READ "${scriptname}" script)
 
46
 
 
47
  string(REPLACE ";" "\\\\;" script "${script}")
 
48
  string(REPLACE "\n" "E;" script "${script}")
 
49
 
 
50
  set(count 0)
 
51
  set(regex "^ *(if|elseif) *\\( *testname +STREQUAL +\\\"*([^\\\"\\)]+)\\\"* *\\) *# *(fail|pass) *E$")
 
52
 
 
53
  foreach(line ${script})
 
54
    if(line MATCHES "${regex}")
 
55
      math(EXPR count "${count} + 1")
 
56
      string(REGEX REPLACE "${regex}" "\\2" testname "${line}")
 
57
      string(REGEX REPLACE "${regex}" "\\3" expected_result "${line}")
 
58
      execute_one_script_test(${scriptname} ${testname} ${expected_result})
 
59
    endif()
 
60
  endforeach()
 
61
 
 
62
  set(${result} ${count} PARENT_SCOPE)
 
63
endfunction()