Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Tweak creation of config file and layout of some files in tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Jun 19, 2014
1 parent 5743275 commit 78a5a6a
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ncss.xml
configuredVars.php
TestConfig.php
37 changes: 21 additions & 16 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@
# limitations under the License.
#=============================================================================

# Create the configuredVars.php file used for testing
# Create the TestConfig.php file used for testing
option(MIDAS_TEST_COVERAGE "Perform xdebug coverage. Only turn on if you need coverage." OFF)

file(WRITE ${CMAKE_SOURCE_DIR}/tests/configuredVars.php
"<?php
define('CMAKE_BINARY_DIR', '${CMAKE_BINARY_DIR}');
")
file(APPEND ${CMAKE_SOURCE_DIR}/tests/configuredVars.php "define('MIDAS_TEST_COVERAGE', ")
if(MIDAS_TEST_COVERAGE)
file(APPEND ${CMAKE_SOURCE_DIR}/tests/configuredVars.php "true")
set(MIDAS_TEST_COVERAGE_LITERAL "true")
else()
file(APPEND ${CMAKE_SOURCE_DIR}/tests/configuredVars.php "false")
set(MIDAS_TEST_COVERAGE_LITERAL "false")
endif()
file(APPEND ${CMAKE_SOURCE_DIR}/tests/configuredVars.php "); ?>")
configure_file(${CMAKE_SOURCE_DIR}/tests/TestConfig.php.in ${CMAKE_SOURCE_DIR}/tests/TestConfig.php)

# Create the xdebug coverage directory that CTest expects
if(NOT EXISTS ${CMAKE_BINARY_DIR}/xdebugCoverage)
Expand Down Expand Up @@ -90,7 +84,7 @@ function(add_midas_style_test TestName TestDir)

add_test(
${TestName}TrailingSpaces
${PHP} ${CMAKE_SOURCE_DIR}/tests/library/MIDASStyleChecker.php --src ${TestDir}
${PHP} ${CMAKE_SOURCE_DIR}/tests/TrailingSpaces.php --src ${TestDir}
)
set_tests_properties(
${TestName}TrailingSpaces PROPERTIES
Expand All @@ -99,16 +93,27 @@ function(add_midas_style_test TestName TestDir)
endif()
endfunction(add_midas_style_test)

if(NOT WIN32)
# This test is not designed to work on windows for some reason
add_midas_test( KWUtils KWUtilsTest.php )
endif()

add_midas_style_test( StyleKWUtils ${CMAKE_SOURCE_DIR}/library/KWUtils.php )
add_midas_style_test( StyleTestsBootstrap ${CMAKE_SOURCE_DIR}/tests/bootstrap.php )
add_midas_style_test( StyleTestsControllerTestCase ${CMAKE_SOURCE_DIR}/tests/ControllerTestCase.php )
add_midas_style_test( StyleTestsDatabaseSetup ${CMAKE_SOURCE_DIR}/tests/DatabaseSetup.php )
add_midas_style_test( StyleTestsDatabaseTestCase ${CMAKE_SOURCE_DIR}/tests/DatabaseTestCase.php )
add_midas_style_test( StyleTestsUtf8tools ${CMAKE_SOURCE_DIR}/tests/Utf8tools.php )
add_midas_style_test( StyleTestsKWUtilsTest ${CMAKE_SOURCE_DIR}/tests/KWUtilsTest.php )
add_midas_style_test( StyleTestsTrailingSpaces ${CMAKE_SOURCE_DIR}/tests/TrailingSpaces.php )
add_midas_style_test( StyleTestsUTF8Tools ${CMAKE_SOURCE_DIR}/tests/UTF8Tools.php )

add_test(Utf8encoding ${PHP} ${CMAKE_SOURCE_DIR}/tests/Utf8tools.php --src ${CMAKE_SOURCE_DIR})
if(NOT WIN32)
# This test is not designed to work on Windows for some reason
add_midas_test( KWUtils KWUtilsTest.php )
endif()

add_test(UTF8Encoding ${PHP} ${CMAKE_SOURCE_DIR}/tests/UTF8Tools.php --src ${CMAKE_SOURCE_DIR})
set_tests_properties(
Utf8encoding PROPERTIES
UTF8Encoding PROPERTIES
FAIL_REGULAR_EXPRESSION "ERROR;WARNING"
)

add_subdirectory( library )
2 changes: 1 addition & 1 deletion tests/ControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
=========================================================================*/

require_once dirname(__FILE__).'/bootstrap.php';
require_once dirname(__FILE__).'/configuredVars.php';
require_once dirname(__FILE__).'/TestConfig.php';
require_once BASE_PATH.'/core/controllers/components/UtilityComponent.php';

/** main controller test element*/
Expand Down
2 changes: 1 addition & 1 deletion tests/DatabaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
=========================================================================*/

require_once dirname(__FILE__).'/bootstrap.php';
require_once dirname(__FILE__).'/configuredVars.php';
require_once dirname(__FILE__).'/TestConfig.php';
require_once BASE_PATH.'/core/controllers/components/UtilityComponent.php';

/** main models test element */
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/TestConfig.php.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

define('CMAKE_BINARY_DIR', '@CMAKE_BINARY_DIR@');
define('MIDAS_TEST_COVERAGE', @MIDAS_TEST_COVERAGE_LITERAL@);
File renamed without changes.
24 changes: 12 additions & 12 deletions tests/Utf8tools.php → tests/UTF8Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
limitations under the License.
=========================================================================*/

/** tools for detecting non utf8 files and transforming non utf8 files to utf8. */
class Utf8tools
/** tools for detecting non UTF-8 files and transforming non UTF-8 files to UTF-8. */
class UTF8Tools
{
protected $excludedDirs = array('_build', '_test', '.git', 'bin', 'build', 'data', 'library', 'log', 'tmp');
protected $excludedExts = array('gif', 'ico', 'ini', 'jar', 'jpeg', 'jpg', 'keystore', 'png', 'psd', 'swc', 'swf');
Expand All @@ -28,7 +28,7 @@ class Utf8tools
/**
* return true if the string is UTF8 encoded.
*/
protected function isUtf8($str)
protected function isUTF8($str)
{
$len = strlen($str);
for($i = 0; $i < $len; $i++)
Expand Down Expand Up @@ -131,20 +131,20 @@ function getMatchingFilesRecursive($src, $dir = '')

/**
* create a listing of files, should be called from the MIDAS BASE DIR, checks
* them for non-utf8 encoded files, and if createUtf8Version is true,
* will create another file in the same dir alongside any non-utf8 file
* that is utf8 encoded and has the same name as the non-utf8 file, with
* an extension of .utf8 .
* them for non-UTF-8 encoded files, and if createUtf8Version is true,
* will create another file in the same dir alongside any non-UTF-8 file
* that is UTF-8 encoded and has the same name as the non-UTF-8 file, with
* an extension of .utf8.
*/
public function listNonUtf8Files($srcDir, $createUtf8Version = false)
{
$allFiles = $this->getMatchingFilesRecursive($srcDir);
foreach($allFiles as $file)
{
$filecontents = file_get_contents($file);
if(!$this->isUtf8($filecontents))
if(!$this->isUTF8($filecontents))
{
echo "ERROR: non-utf8 characters found in ".$file."\n";
echo "ERROR: non-UTF-8 characters found in ".$file."\n";
if($createUtf8Version)
{
$utf8Version = mb_convert_encoding($filecontents, 'UTF-8');
Expand All @@ -156,13 +156,13 @@ public function listNonUtf8Files($srcDir, $createUtf8Version = false)
}
}

// don't create utf8 versions by default
// do not create UTF-8 versions by default
$create = false;
if(sizeof($argv) > 3 || sizeof($argv) < 2)
{
if($argv[3] !== 'create')
{
echo "Usage:\n\nphp Utf8tools.php --src <MIDAS SOURCE DIR> [create]\n\noptional argument create says to create utf8 versions on non utf8 encoded files\n";
echo "Usage:\n\nphp UTF8Tools.php --src <MIDAS SOURCE DIR> [create]\n\noptional argument create says to create UTF-8 versions on non UTF-8 encoded files\n";
exit();
}
else
Expand All @@ -171,5 +171,5 @@ public function listNonUtf8Files($srcDir, $createUtf8Version = false)
}
}
$srcDir = $argv[2];
$utf8 = new Utf8tools();
$utf8 = new UTF8Tools();
$utf8->listNonUtf8Files($srcDir, $create);
27 changes: 0 additions & 27 deletions tests/library/CMakeLists.txt

This file was deleted.

0 comments on commit 78a5a6a

Please sign in to comment.