cmTest.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTest.h"
  11. #include "cmSystemTools.h"
  12. #include "cmake.h"
  13. #include "cmMakefile.h"
  14. //----------------------------------------------------------------------------
  15. cmTest::cmTest(cmMakefile* mf)
  16. {
  17. this->Makefile = mf;
  18. this->OldStyle = true;
  19. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  20. this->Backtrace = new cmListFileBacktrace;
  21. this->Makefile->GetBacktrace(*this->Backtrace);
  22. }
  23. //----------------------------------------------------------------------------
  24. cmTest::~cmTest()
  25. {
  26. delete this->Backtrace;
  27. }
  28. //----------------------------------------------------------------------------
  29. cmListFileBacktrace const& cmTest::GetBacktrace() const
  30. {
  31. return *this->Backtrace;
  32. }
  33. //----------------------------------------------------------------------------
  34. void cmTest::SetName(const char* name)
  35. {
  36. if ( !name )
  37. {
  38. name = "";
  39. }
  40. this->Name = name;
  41. }
  42. //----------------------------------------------------------------------------
  43. void cmTest::SetCommand(std::vector<std::string> const& command)
  44. {
  45. this->Command = command;
  46. }
  47. //----------------------------------------------------------------------------
  48. const char *cmTest::GetProperty(const char* prop) const
  49. {
  50. bool chain = false;
  51. const char *retVal =
  52. this->Properties.GetPropertyValue(prop, cmProperty::TEST, chain);
  53. if (chain)
  54. {
  55. return this->Makefile->GetProperty(prop,cmProperty::TEST);
  56. }
  57. return retVal;
  58. }
  59. //----------------------------------------------------------------------------
  60. bool cmTest::GetPropertyAsBool(const char* prop) const
  61. {
  62. return cmSystemTools::IsOn(this->GetProperty(prop));
  63. }
  64. //----------------------------------------------------------------------------
  65. void cmTest::SetProperty(const char* prop, const char* value)
  66. {
  67. if (!prop)
  68. {
  69. return;
  70. }
  71. this->Properties.SetProperty(prop, value, cmProperty::TEST);
  72. }
  73. //----------------------------------------------------------------------------
  74. void cmTest::AppendProperty(const char* prop, const char* value)
  75. {
  76. if (!prop)
  77. {
  78. return;
  79. }
  80. this->Properties.AppendProperty(prop, value, cmProperty::TEST);
  81. }
  82. //----------------------------------------------------------------------------
  83. void cmTest::DefineProperties(cmake *cm)
  84. {
  85. cm->DefineProperty
  86. ("ENVIRONMENT", cmProperty::TEST,
  87. "Specify environment variables that should be defined for running "
  88. "a test.",
  89. "If set to a list of environment variables and values of the form "
  90. "MYVAR=value those environment variables will be defined while "
  91. "running the test. The environment is restored to its previous state "
  92. "after the test is done.");
  93. cm->DefineProperty
  94. ("FAIL_REGULAR_EXPRESSION", cmProperty::TEST,
  95. "If the output matches this regular expression the test will fail.",
  96. "If set, if the output matches one of "
  97. "specified regular expressions, the test will fail."
  98. "For example: PASS_REGULAR_EXPRESSION \"[^a-z]Error;ERROR;Failed\"");
  99. cm->DefineProperty
  100. ("LABELS", cmProperty::TEST,
  101. "Specify a list of text labels associated with a test.",
  102. "The list is reported in dashboard submissions.");
  103. cm->DefineProperty
  104. ("MEASUREMENT", cmProperty::TEST,
  105. "Specify a CDASH measurement and value to be reported for a test.",
  106. "If set to a name then that name will be reported to CDASH as a "
  107. "named measurement with a value of 1. You may also specify a value "
  108. "by setting MEASUREMENT to \"measurement=value\".");
  109. cm->DefineProperty
  110. ("PASS_REGULAR_EXPRESSION", cmProperty::TEST,
  111. "The output must match this regular expression for the test to pass.",
  112. "If set, the test output will be checked "
  113. "against the specified regular expressions and at least one of the"
  114. " regular expressions has to match, otherwise the test will fail.");
  115. cm->DefineProperty
  116. ("TIMEOUT", cmProperty::TEST,
  117. "How many seconds to allow for this test.",
  118. "This property if set will limit a test to not take more than "
  119. "the specified number of seconds to run. If it exceeds that the "
  120. "test process will be killed and ctest will move to the next test. "
  121. "This setting takes precedence over "
  122. "CTEST_TESTING_TIMEOUT.");
  123. cm->DefineProperty
  124. ("WILL_FAIL", cmProperty::TEST,
  125. "If set to true, this will invert the pass/fail flag of the test.",
  126. "This property can be used for tests that are expected to fail and "
  127. "return a non zero return code.");
  128. }