From e6ed36f739eaa29b827c9bc20d4434d5aa85ac59 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 12 Feb 2017 14:21:58 +0000 Subject: [PATCH] Add solvespace-debugtool, to expose some internals via CLI. --- test/CMakeLists.txt | 21 +++++++++++++++++++-- test/debugtool.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/debugtool.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3b2e05d..d29d7cc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,3 @@ -# test suite - include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) @@ -9,6 +7,8 @@ foreach(pkg_config_lib CAIRO) link_directories(${${pkg_config_lib}_LIBRARY_DIRS}) endforeach() +# test suite + set(testsuite_SOURCES harness.cpp core/expr/test.cpp @@ -110,3 +110,20 @@ if(ENABLE_COVERAGE) COMMENT "Generating coverage report" VERBATIM) endif() + +# debug runner + +set(debugtool_SOURCES + debugtool.cpp +) + +add_executable(solvespace-debugtool + ${debugtool_SOURCES} + $) + +target_link_libraries(solvespace-debugtool + solvespace-core + solvespace-headless) + +add_dependencies(solvespace-debugtool + resources) diff --git a/test/debugtool.cpp b/test/debugtool.cpp new file mode 100644 index 0000000..9553dbd --- /dev/null +++ b/test/debugtool.cpp @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------------- +// Our entry point for exposing various internal mechanisms. +// +// Copyright 2017 whitequark +//----------------------------------------------------------------------------- +#include "solvespace.h" + +int main(int argc, char **argv) { + std::vector args = InitPlatform(argc, argv); + + if(args.size() == 3 && args[1] == "expr") { + std::string expr = args[2]; + fprintf(stderr, "%g\n", Expr::From(expr.c_str(), false)->Eval()); + FreeAllTemporary(); + } else { + fprintf(stderr, "Usage: %s \n", args[0].c_str()); +//-----------------------------------------------------------------------------> 80 col */ + fprintf(stderr, R"( + Commands: + expr [expr] + Evaluate an expression. +)"); + } + + return 0; +}