cmTest.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmTest.h"
  14. #include "cmSystemTools.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. //----------------------------------------------------------------------------
  18. cmTest::cmTest()
  19. {
  20. this->Makefile = 0;
  21. this->OldStyle = true;
  22. }
  23. //----------------------------------------------------------------------------
  24. cmTest::~cmTest()
  25. {
  26. }
  27. //----------------------------------------------------------------------------
  28. void cmTest::SetName(const char* name)
  29. {
  30. if ( !name )
  31. {
  32. name = "";
  33. }
  34. this->Name = name;
  35. }
  36. //----------------------------------------------------------------------------
  37. void cmTest::SetCommand(std::vector<std::string> const& command)
  38. {
  39. this->Command = command;
  40. }
  41. //----------------------------------------------------------------------------
  42. const char *cmTest::GetProperty(const char* prop) const
  43. {
  44. bool chain = false;
  45. const char *retVal =
  46. this->Properties.GetPropertyValue(prop, cmProperty::TEST, chain);
  47. if (chain)
  48. {
  49. return this->Makefile->GetProperty(prop,cmProperty::TEST);
  50. }
  51. return retVal;
  52. }
  53. //----------------------------------------------------------------------------
  54. bool cmTest::GetPropertyAsBool(const char* prop) const
  55. {
  56. return cmSystemTools::IsOn(this->GetProperty(prop));
  57. }
  58. //----------------------------------------------------------------------------
  59. void cmTest::SetProperty(const char* prop, const char* value)
  60. {
  61. if (!prop)
  62. {
  63. return;
  64. }
  65. this->Properties.SetProperty(prop, value, cmProperty::TEST);
  66. }
  67. //----------------------------------------------------------------------------
  68. void cmTest::AppendProperty(const char* prop, const char* value)
  69. {
  70. if (!prop)
  71. {
  72. return;
  73. }
  74. this->Properties.AppendProperty(prop, value, cmProperty::TEST);
  75. }
  76. //----------------------------------------------------------------------------
  77. void cmTest::SetMakefile(cmMakefile* mf)
  78. {
  79. this->Makefile = mf;
  80. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  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 DART measurement and value to be reported for a test.",
  106. "If set to a name then that name will be reported to DART 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 DART_TESTING_TIMEOUT and "
  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. }