Commit 6ccb6410 authored by John Tourtellott's avatar John Tourtellott
Browse files

Replace os-specific shell scripts with cmake script

parent 610bd74b
Pipeline #210218 waiting for manual action with stages
# Script for running modelbuilder test script, expected it to generate
# a file as a result.
# Requred variables:
# EXECUTABLE: path to the modelbuilder executable
# EXPECTED_FILE: path to the file that modelbuilder generates
# DATA_DIR: argument to pass to --data-directory
# TEST_DIR: argument to pass to --test-directory
# TEST_SCRIPT: path to the test (.xml) file to play
# Remove expected file before running modelbuilder
if (EXISTS ${EXPECTED_FILE})
file(REMOVE ${EXPECTED_FILE})
endif ()
# Run modelbuilder
execute_process(
COMMAND
${EXECUTABLE}
"-dr"
"--data-directory=${DATA_DIR}"
"--test-directory=${TEST_DIR}"
"--test-script=${TEST_SCRIPT}"
"--exit"
RESULT_VARIABLE error_code
)
if (error_code)
message(FATAL_ERROR "Modelbuilder returned error code ${error_code}.")
endif ()
# Check if expected file was generated
if (NOT EXISTS ${EXPECTED_FILE})
message(FATAL_ERROR "The expected file (${EXPECTED_FILE}) was not generated.")
endif ()
......@@ -33,45 +33,39 @@ Tests that extracted modelbuilder executable can import smtk python modules.
add_package_import_test(generator)
```
This test runs modelbuilder and checks if it can import a minimal smtk operation,
which requires the python environment to be configured correctly. The logic is
a bit circuitous:
which requires the python environment to be configured correctly.
* The test itself runs a shell script, which can be found in the scripts
subfolder.
* The arguments passed in to the shell script form a modelbuilder execution
command that runs an xml script, which is also in the scripts subfolder.
* The test command runs a cmake script that runs the modelbuilder executable.
* Variables passed to the cmake script specify the paths to the executable,
the xml script, and other needed info.
* The xml script invokes the modelbuilder "Import Python Operation..." menu
item and selects a python file (which is also in the scripts subfolder).
* If the import-operation is successful, the python operation creates a
small text file in the test directory.
* The shell scripts verifies that the text file has been generated.
item and selects a python file "minimum_operation.py" in the scripts
subfolder).
* If the import operation is successful, a small text file is generated in
the test directory.
#]==]
function (add_package_import_test generator)
set(extract_dir "${modelbuilder_extract_root}/modelbuilder-${generator}/test-extracted")
set(this_dir "${CMAKE_SOURCE_DIR}/cmake")
set(test_dir "${CMAKE_BINARY_DIR}/Testing/Temporary")
set(exe_path "bin/modelbuilder")
if (APPLE)
set(exe_path "modelbuilder.app/Contents/MacOS/modelbuilder")
endif ()
if (WIN32)
set(shell_script "import_python_test.ps1")
else ()
set(shell_script "import_python_test.sh")
endif ()
add_test(
NAME "package-import-test-${generator}"
COMMAND "${this_dir}/scripts/${shell_script}"
"${extract_dir}/${exe_path}"
"-dr"
"--data-directory=${this_dir}/scripts"
"--test-directory=${CMAKE_BINARY_DIR}/Testing/Temporary"
"--test-script=${this_dir}/scripts/import_minimum_operation.xml"
"--exit"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Testing/Temporary"
COMMAND
"${CMAKE_COMMAND}"
"-DEXECUTABLE=${extract_dir}/${exe_path}"
"-DEXPECTED_FILE=${test_dir}/minimum_operation.txt"
"-DDATA_DIR=${this_dir}/scripts"
"-DTEST_DIR=${test_dir}"
"-DTEST_SCRIPT=${this_dir}/scripts/import_minimum_operation.xml"
"-P" "${this_dir}/import_pythonop.cmake"
WORKING_DIRECTORY "${test_dir}"
)
set_tests_properties("package-import-test-${generator}"
......
# Script for running import-python test
# - The full set of input arguments are the
# command + arguments to run modelbuilder.
# - The commands are expected to create a file
# minimum_operation.txt in the working directory
# Remove expected file from the working directory
Set-Variable -Name filename -Value "minimum_operation.txt"
Remove-Item -Force ${filename}
# Run the input arguments, which should constitute a
# modelbuilder command that runs an xml script and exits.
$args
# Check for the expected file in the working directory
if ( Test-Path ${filename} -PathType Leaf)
{
exit 0
}
Write-Host "ERROR: File ${filename} NOT found"
exit 1
#!/usr/bin/env bash
# bash script for running import-python test
# - The full set of input arguments are the
# command + arguments to run modelbuilder.
# - The commands are expected to create a file
# minimum_operation.txt in the working directory
# Remove expected file from the working directory
filename=minimum_operation.txt
rm -f ${filename}
# Run the input arguments, which should constitute a
# modelbuilder command that runs an xml script and exits.
$*
# Check for the expected file in the working directory
if [ -f "${filename}" ]; then
exit 0
fi
echo "ERROR: File ${filename} NOT found"
exit 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment