Skip to content

Commit 42f9aee

Browse files
authored
Merge pull request #667 from ferdnyc/debug-envvar
Settings: Support LIBOPENSHOT_DEBUG envvar
2 parents 6a004ed + 97c2530 commit 42f9aee

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ option(DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF)
8080
option(ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF)
8181

8282
option(ENABLE_PARALLEL_CTEST "Run CTest using multiple processors" ON)
83+
option(VERBOSE_TESTS "Run CTest with maximum verbosity" OFF)
8384
option(ENABLE_COVERAGE "Scan test coverage using gcov and report" OFF)
8485

8586
option(ENABLE_DOCS "Build API documentation (requires Doxygen)" ON)
@@ -187,9 +188,12 @@ if(BUILD_TESTING)
187188
ProcessorCount(CPU_COUNT)
188189
if(CPU_COUNT GREATER 1)
189190
add_feature_info("Parallel tests" TRUE "Unit tests can use ${CPU_COUNT} processors")
190-
set(CTEST_OPTIONS "-j${CPU_COUNT}")
191+
list(APPEND CTEST_OPTIONS "-j${CPU_COUNT}")
191192
endif()
192193
endif()
194+
if(VERBOSE_TESTS)
195+
list(APPEND CTEST_OPTIONS "-VV")
196+
endif()
193197
add_subdirectory(tests)
194198
endif()
195199
add_feature_info("Unit tests" ${BUILD_TESTING} "Compile unit tests for library functions")

src/Settings.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2929
*/
3030

31+
#include <cstdlib> // For std::getenv
32+
3133
#include "Settings.h"
3234

33-
using namespace std;
3435
using namespace openshot;
3536

36-
3737
// Global reference to Settings
38-
Settings *Settings::m_pInstance = NULL;
38+
Settings *Settings::m_pInstance = nullptr;
3939

4040
// Create or Get an instance of the settings singleton
4141
Settings *Settings::Instance()
@@ -53,6 +53,9 @@ Settings *Settings::Instance()
5353
m_pInstance->HW_EN_DEVICE_SET = 0;
5454
m_pInstance->PLAYBACK_AUDIO_DEVICE_NAME = "";
5555
m_pInstance->DEBUG_TO_STDERR = false;
56+
auto env_debug = std::getenv("LIBOPENSHOT_DEBUG");
57+
if (env_debug != nullptr)
58+
m_pInstance->DEBUG_TO_STDERR = true;
5659
}
5760

5861
return m_pInstance;

src/Settings.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,7 @@
3131
#ifndef OPENSHOT_SETTINGS_H
3232
#define OPENSHOT_SETTINGS_H
3333

34-
35-
#include <iostream>
36-
#include <iomanip>
37-
#include <fstream>
38-
#include <cstdlib>
3934
#include <string>
40-
#include <sstream>
41-
#include <cstdio>
42-
#include <ctime>
43-
#include <zmq.hpp>
44-
#include <unistd.h>
45-
#include <OpenShotAudio.h>
46-
4735

4836
namespace openshot {
4937

@@ -118,7 +106,7 @@ namespace openshot {
118106
/// The current install path of OpenShot (needs to be set when using Timeline(path), since certain
119107
/// paths depend on the location of OpenShot transitions and files)
120108
std::string PATH_OPENSHOT_INSTALL = "";
121-
109+
122110
/// Whether to dump ZeroMQ debug messages to stderr
123111
bool DEBUG_TO_STDERR = false;
124112

tests/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2525
################################################################################
2626

27+
# Allow spaces in test names
28+
if(POLICY CMP0110)
29+
cmake_policy(SET CMP0110 NEW)
30+
endif()
31+
2732
# Test media path, used by unit tests for input data
2833
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/examples/" TEST_MEDIA_PATH)
2934

@@ -103,6 +108,18 @@ foreach(tname ${OPENSHOT_TESTS})
103108
list(APPEND CATCH2_TEST_TARGETS openshot-${tname}-test)
104109
list(APPEND CATCH2_TEST_NAMES ${tname})
105110
endforeach()
111+
# Add an additional special-case test, for an envvar-dependent setting
112+
add_test(NAME [=["Settings:Debug logging (enabled)"]=]
113+
COMMAND
114+
openshot-Settings-test "[environment]"
115+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
116+
)
117+
set_tests_properties([=["Settings:Debug logging (enabled)"]=]
118+
PROPERTIES
119+
LABELS Settings
120+
ENVIRONMENT "LIBOPENSHOT_DEBUG=1"
121+
)
122+
106123
# Export target list for coverage use
107124
set(UNIT_TEST_TARGETS ${CATCH2_TEST_TARGETS} PARENT_SCOPE)
108125
set(UNIT_TEST_NAMES ${CATCH2_TEST_NAMES} PARENT_SCOPE)

tests/Settings.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
using namespace openshot;
3636

37-
TEST_CASE( "Default_Constructor", "[libopenshot][settings]" )
37+
TEST_CASE( "Constructor", "[libopenshot][settings]" )
3838
{
3939
// Create an empty color
4040
Settings *s = Settings::Instance();
@@ -43,7 +43,7 @@ TEST_CASE( "Default_Constructor", "[libopenshot][settings]" )
4343
CHECK_FALSE(s->HIGH_QUALITY_SCALING);
4444
}
4545

46-
TEST_CASE( "Change_Settings", "[libopenshot][settings]" )
46+
TEST_CASE( "Change settings", "[libopenshot][settings]" )
4747
{
4848
// Create an empty color
4949
Settings *s = Settings::Instance();
@@ -56,3 +56,12 @@ TEST_CASE( "Change_Settings", "[libopenshot][settings]" )
5656
CHECK(Settings::Instance()->OMP_THREADS == 8);
5757
CHECK(Settings::Instance()->HIGH_QUALITY_SCALING == true);
5858
}
59+
60+
TEST_CASE( "Debug logging", "[libopenshot][settings][environment]")
61+
{
62+
// Check the environment
63+
auto envvar = std::getenv("LIBOPENSHOT_DEBUG");
64+
const auto is_enabled = bool(envvar != nullptr);
65+
66+
CHECK(Settings::Instance()->DEBUG_TO_STDERR == is_enabled);
67+
}

0 commit comments

Comments
 (0)