View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007885CMakeCMakepublic2008-10-29 10:202010-12-14 18:45
ReporterJ. Bedouet 
Assigned ToDavid Cole 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusclosedResolutionfixed 
PlatformOSOS Version
Product VersionCMake-2-6 
Target VersionFixed in Version 
Summary0007885: Set environment before running a test
DescriptionIt 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")
Additional InformationCf. mailing list.
http://www.cmake.org/pipermail/cmake/2008-October/024904.html [^]
TagsNo tags attached.
Attached Files

 Relationships
has duplicate 0006391closedDavid Cole CTest: set environment variables for test session 

  Notes
(0014198)
David Cole (manager)
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 (manager)
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 (manager)
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 (manager)
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 (reporter)
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 (developer)
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 (developer)
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 (manager)
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 (manager)
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 (developer)
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 (manager)
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 (manager)
2010-12-14 18:45

Closing bugs that have been resolved for more than 3 months without any further updates.

 Issue History
Date Modified Username Field Change
2008-10-29 10:20 J. Bedouet New Issue
2008-11-08 18:00 Bill Hoffman Status new => assigned
2008-11-08 18:00 Bill Hoffman Assigned To => Bill Hoffman
2008-11-25 15:55 David Cole Assigned To Bill Hoffman => David Cole
2008-11-26 14:39 David Cole Note Added: 0014198
2008-11-26 15:06 David Cole Note Added: 0014199
2008-11-26 15:41 David Cole Note Added: 0014200
2008-11-26 15:41 David Cole Note Deleted: 0014200
2008-11-26 15:42 David Cole Note Added: 0014201
2008-11-28 10:50 David Cole Note Added: 0014223
2008-11-28 17:00 J. Bedouet Note Added: 0014229
2009-01-22 14:06 David Cole Status assigned => resolved
2009-01-22 14:06 David Cole Resolution open => fixed
2009-02-17 00:17 Philip Lowman Note Added: 0015009
2009-02-17 00:17 Philip Lowman Status resolved => feedback
2009-02-17 00:17 Philip Lowman Resolution fixed => reopened
2009-02-17 00:18 Philip Lowman Note Added: 0015010
2009-02-17 09:21 Bill Hoffman Note Added: 0015011
2009-02-17 09:21 Bill Hoffman Status feedback => closed
2009-02-17 09:21 Bill Hoffman Resolution reopened => fixed
2009-02-17 09:30 Bill Hoffman Note Added: 0015012
2009-02-17 09:34 Bill Hoffman Status closed => assigned
2009-02-18 07:52 Philip Lowman Note Added: 0015126
2009-04-03 11:42 David Cole Relationship added has duplicate 0006391
2009-04-03 11:43 David Cole Note Added: 0015900
2009-04-03 11:43 David Cole Status assigned => resolved
2010-12-14 18:45 David Cole Note Added: 0024002
2010-12-14 18:45 David Cole Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team