MantisBT - CMake
View Issue Details
0007885CMakeCMakepublic2008-10-29 10:202010-12-14 18:45
J. Bedouet 
David Cole 
normalfeatureN/A
closedfixed 
CMake-2-6 
 
0007885: Set environment before running a test
It would be useful to set environment variables before running a test. Somewhat like
 
ADD_TEST (TestEnv1 testEnv)
SET_TEST_PROPERTIES (TestEnv1 PROPERTIES ENV TEST_ENV="testEnvValue1")
SET_TEST_PROPERTIES (TestEnv1 PROPERTIES WILL_FAIL true)
 
ADD_TEST (TestEnv2 testEnv)
SET_TEST_PROPERTIES (TestEnv2 PROPERTIES ENV TEST_ENV="testEnvValue2")
Cf. mailing list.
http://www.cmake.org/pipermail/cmake/2008-October/024904.html [^]
No tags attached.
has duplicate 0006391closed David Cole CTest: set environment variables for test session 
Issue History
2008-10-29 10:20J. BedouetNew Issue
2008-11-08 18:00Bill HoffmanStatusnew => assigned
2008-11-08 18:00Bill HoffmanAssigned To => Bill Hoffman
2008-11-25 15:55David ColeAssigned ToBill Hoffman => David Cole
2008-11-26 14:39David ColeNote Added: 0014198
2008-11-26 15:06David ColeNote Added: 0014199
2008-11-26 15:41David ColeNote Added: 0014200
2008-11-26 15:41David ColeNote Deleted: 0014200
2008-11-26 15:42David ColeNote Added: 0014201
2008-11-28 10:50David ColeNote Added: 0014223
2008-11-28 17:00J. BedouetNote Added: 0014229
2009-01-22 14:06David ColeStatusassigned => resolved
2009-01-22 14:06David ColeResolutionopen => fixed
2009-02-17 00:17Philip LowmanNote Added: 0015009
2009-02-17 00:17Philip LowmanStatusresolved => feedback
2009-02-17 00:17Philip LowmanResolutionfixed => reopened
2009-02-17 00:18Philip LowmanNote Added: 0015010
2009-02-17 09:21Bill HoffmanNote Added: 0015011
2009-02-17 09:21Bill HoffmanStatusfeedback => closed
2009-02-17 09:21Bill HoffmanResolutionreopened => fixed
2009-02-17 09:30Bill HoffmanNote Added: 0015012
2009-02-17 09:34Bill HoffmanStatusclosed => assigned
2009-02-18 07:52Philip LowmanNote Added: 0015126
2009-04-03 11:42David ColeRelationship addedhas duplicate 0006391
2009-04-03 11:43David ColeNote Added: 0015900
2009-04-03 11:43David ColeStatusassigned => resolved
2010-12-14 18:45David ColeNote Added: 0024002
2010-12-14 18:45David ColeStatusresolved => closed

Notes
(0014198)
David Cole   
2008-11-26 14:39   
Initial draft of feature is now in CVS CMake:

/cvsroot/CMake/CMake/Source/cmCTest.cxx,v <-- Source/cmCTest.cxx
new revision: 1.341; previous revision: 1.340
/cvsroot/CMake/CMake/Source/cmCTest.h,v <-- Source/cmCTest.h
new revision: 1.103; previous revision: 1.102
/cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v <-- Source/cmSystemTools.cxx
new revision: 1.386; previous revision: 1.385
/cvsroot/CMake/CMake/Source/cmSystemTools.h,v <-- Source/cmSystemTools.h
new revision: 1.156; previous revision: 1.155
/cvsroot/CMake/CMake/Source/CTest/cmCTestBuildAndTestHandler.cxx,v <-- Source/CTest/cmCTestBuildAndTestHandler.cxx
new revision: 1.23; previous revision: 1.22
/cvsroot/CMake/CMake/Source/CTest/cmCTestTestHandler.cxx,v <-- Source/CTest/cmCTestTestHandler.cxx
new revision: 1.82; previous revision: 1.81
/cvsroot/CMake/CMake/Source/CTest/cmCTestTestHandler.h,v <-- Source/CTest/cmCTestTestHandler.h
new revision: 1.30; previous revision: 1.29
/cvsroot/CMake/CMake/Tests/CMakeLists.txt,v <-- Tests/CMakeLists.txt
new revision: 1.73; previous revision: 1.72
/cvsroot/CMake/CMake/Tests/Environment/CMakeLists.txt,v <-- Tests/Environment/CMakeLists.txt
initial revision: 1.1
/cvsroot/CMake/CMake/Tests/Environment/main.cxx,v <-- Tests/Environment/main.cxx
initial revision: 1.1
(0014199)
David Cole   
2008-11-26 15:06   
I implemented it with the word "ENVIRONMENT" as the name of the test property.

See example/test use in CMake/Tests/Environment/CMakeLists.txt.
(0014201)
David Cole   
2008-11-26 15:42   
$ cvs commit -m "COMP: Using the proper type for local variables can eliminate compiler warnings." Source/cmSystemTools.cxx

/cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v <-- Source/cmSystemTools.cxx
new revision: 1.387; previous revision: 1.386
(0014223)
David Cole   
2008-11-28 10:50   
$ cvs commit -m "STYLE: Fix line length style violation." Source/cmCTest.h

/cvsroot/CMake/CMake/Source/cmCTest.h,v <-- Source/cmCTest.h
new revision: 1.104; previous revision: 1.103
(0014229)
J. Bedouet   
2008-11-28 17:00   
It works fine for me.
Thanks a lot.

Will it to be integrated to a future release of CMake 2.6 ?
(0015009)
Philip Lowman   
2009-02-17 00:17   
There's an issue with the patch. For some reason it doesn't seem to work for executing "ctest", but works fine for me on "make test". Also the property is not documented.

lowman@locke:~/tmp/cmake_tests/TestEnv/build$ make test
Running tests...
Start processing tests
Test project /home/lowman/tmp/cmake_tests/TestEnv/build
  1/ 1 Testing foo .......................... Passed

100% tests passed, 0 tests failed out of 1
lowman@locke:~/tmp/cmake_tests/TestEnv/build$ ctest
Start processing tests
Test project /home/lowman/tmp/cmake_tests/TestEnv/build
  1/ 1 Testing foo ***Failed

0% tests passed, 1 tests failed out of 1

The following tests FAILED:
      1 - foo (Failed)
Errors while running CTest

=====================
CMakeLists.txt
=====================
project(Foo)
cmake_minimum_required(VERSION 2.6)
enable_testing(true)
add_executable(foo foo.cc)
add_test(foo foo)
set_tests_properties(foo PROPERTIES ENVIRONMENT foo=bar)

============================
foo.cc:
============================
#include <iostream>
#include <stdlib.h>
int main(int argc, char const* argv[])
{
   char *foo = getenv("foo");
   if(foo) std::cout << "foo = " << foo << std::endl;
   else return 1;
   return 0;
}
(0015010)
Philip Lowman   
2009-02-17 00:18   
Index: cmTest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTest.cxx,v
retrieving revision 1.11
diff -u -b -B -u -r1.11 cmTest.cxx
--- cmTest.cxx 7 Jan 2009 15:41:37 -0000 1.11
+++ cmTest.cxx 17 Feb 2009 05:16:51 -0000
@@ -122,6 +122,14 @@
      "by setting MEASUREMENT to \"measurement=value\".");
 
   cm->DefineProperty
+ ("ENVIRONMENT", cmProperty::TEST,
+ "Specify environment variables that should be defined before running "
+ "a test.",
+ "If set to a list of environment variables and values of the form "
+ "MYVAR=value those environment variables will be defined while "
+ "running the test.");
+
+ cm->DefineProperty
     ("PASS_REGULAR_EXPRESSION", cmProperty::TEST,
      "The output must match this regular expression for the test to pass.",
      "If set, the test output will be checked "
(0015011)
Bill Hoffman   
2009-02-17 09:21   
This is closed. Just because it is not yet in a release does not mean the bug can not be closed. This will be in 2.8 when that comes out.
(0015012)
Bill Hoffman   
2009-02-17 09:30   
Did you run the correct ctest?

ctest --version

make test will use a full path to ctest.
(0015126)
Philip Lowman   
2009-02-18 07:52   
Yes, I was running the wrong version of ctest. Can't believe this didn't occur to me.
(0015900)
David Cole   
2009-04-03 11:43   
Fixed in CVS HEAD of CMake

$ cvs commit -m "BUG: Fix documentation deficiency noted in issue 0007885. Thanks to Philip Lowman for the gist of the patch." Source/cmTest.cxx

/cvsroot/CMake/CMake/Source/cmTest.cxx,v <-- Source/cmTest.cxx
new revision: 1.14; previous revision: 1.13
(0024002)
David Cole   
2010-12-14 18:45   
Closing bugs that have been resolved for more than 3 months without any further updates.