diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 1564894..402129b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -16,7 +16,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install pytest git+https://github.com/llnl/clippy@master + # python -m pip install pytest git+https://github.com/llnl/clippy@master + python -m pip install pytest git+https://github.com/llnl/clippy@sbromberger/stream-stderr - name: Install Boost @@ -47,14 +48,15 @@ jobs: # git clone https://github.com/LLNL/clippy-cpp --branch $GITHUB_HEAD_REF $TMPDIR mkdir -p build - cd build && cmake -DBOOST_ROOT=$BOOST_ROOT .. && make && cd .. + cd build && cmake -DMODERN_CMAKE_BUILD_TESTING=ON -DBUILD_TESTING=ON -DBOOST_ROOT=$BOOST_ROOT .. && make && cd .. ls -l build/test BACKEND=$PWD/build/test echo "BACKEND=$BACKEND" >> $GITHUB_ENV - name: Run Python test framework env: - CLIPPY_BACKEND_PATH: ${{ env.BACKEND }} + CLIPPY_BACKEND_PATH: ${{ github.workspace }}/build/test + # CLIPPY_BACKEND_PATH: ${{ env.BACKEND }} run: | - echo "backend = $BACKEND" + echo "backend = $CLIPPY_BACKEND_PATH" pytest . diff --git a/.gitignore b/.gitignore index a886cab..62db49e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store /.cache /**/build +/**/build.* /.idea/ CMakeDoxyfile.in CMakeDoxygenDefaults.cmake diff --git a/test/TestBag/insert.cpp b/test/TestBag/insert.cpp index ee6921c..031a978 100644 --- a/test/TestBag/insert.cpp +++ b/test/TestBag/insert.cpp @@ -5,9 +5,6 @@ #include "clippy/clippy.hpp" #include -#include - -namespace boostjsn = boost::json; static const std::string class_name = "ClippyBag"; static const std::string method_name = "insert"; diff --git a/test/TestBag/remove_if.cpp b/test/TestBag/remove_if.cpp index 87a8c52..9bcb6ab 100644 --- a/test/TestBag/remove_if.cpp +++ b/test/TestBag/remove_if.cpp @@ -3,10 +3,8 @@ // // SPDX-License-Identifier: MIT -#include #include #include -#include #include #include // #include @@ -37,7 +35,8 @@ int main(int argc, char **argv) { auto apply_jl = [&jlrule](int value) { boostjsn::object data; data["value"] = value; - return truthy(jlrule.apply(jsonlogic::json_accessor(std::move(data)))); + auto res = jlrule.apply(jsonlogic::json_accessor(data)); + return jsonlogic::unpack_value(res); }; the_bag.remove_if(apply_jl); diff --git a/test/TestGraph/CMakeLists.txt b/test/TestGraph/CMakeLists.txt index edfaff4..c083d02 100644 --- a/test/TestGraph/CMakeLists.txt +++ b/test/TestGraph/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_BUILD_TYPE Debug) + + add_test(TestGraph __init__) add_test(TestGraph __str__) # add_test(TestGraph assign) diff --git a/test/TestGraph/where.cpp b/test/TestGraph/where.cpp index 47c5034..86f3061 100644 --- a/test/TestGraph/where.cpp +++ b/test/TestGraph/where.cpp @@ -8,52 +8,67 @@ #include #include "clippy/selector.hpp" +#include "jsonlogic/logic.hpp" #include "testgraph.hpp" template auto parse_where_expression(M& mvmap_, boost::json::object& expression, boost::json::object& submission_data) { - std::cerr << " parse_where_expression: expression: " << expression - << std::endl; + // std::cerr << " parse_where_expression: expression: " << expression + // << std::endl; boost::json::object exp2(expression); + std::shared_ptr jlrule = + std::make_shared( + jsonlogic::create_logic(exp2["rule"])); + // std::cerr << "past create_logic\n"; + auto vars = jlrule->variable_names(); // boost::json::object submission_data{}; - std::vector vars; + // jsonlogic::any_expr expression_rule_; // we use expression_rule_ (and expression_rule; see below) in order to avoid // having to recompute this every time we call the lambda. - jsonlogic::logic_rule jlrule = jsonlogic::create_logic(exp2["rule"]); + // std::tie(expression_rule_, vars, std::ignore) = + // jsonlogic::create_logic(exp2["rule"]); - std::cerr << "parse_where: # of vars: " << vars.size() << std::endl; - for (const auto& var : vars) { - std::cerr << " apply_jl var dump: var: " << var << std::endl; - } + // this works around a deficiency in C++ compilers where + // unique pointers moved into a lambda cannot be moved into + // an std::function. + // jsonlogic::expr* rawexpr = expression_rule_.release(); + // std::shared_ptr expression_rule{rawexpr}; + // std::shared_ptr jlshared{&jlrule}; - auto apply_jl = [rule=std::move(jlrule), vars, &mvmap_, + // std::cerr << "parse_where: # of vars: " << vars.size() << std::endl; + // for (const auto& var : vars) { + // std::cerr << " apply_jl var dump: var: " << var << std::endl; + // } + + auto apply_jl = [&expression, jlrule, &mvmap_, &submission_data](mvmap::locator loc) mutable { - std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl; + auto vars = jlrule->variable_names(); + // std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl; for (const auto& var : vars) { - std::cerr << " apply_jl: var: " << var << std::endl; + // std::cerr << " apply_jl: var: " << var << std::endl; auto var_sel = selector(std::string(var)); - std::cerr << " apply_jl: var_sel = " << var_sel << std::endl; + // std::cerr << " apply_jl: var_sel = " << var_sel << std::endl; // if (!var_sel.headeq("node")) { // std::cerr << "selector is not a node selector; skipping." << // std::endl; continue; // } auto var_tail = var_sel.tail().value(); std::string var_str = std::string(var_sel); - std::cerr << " apply_jl: var: " << var_sel << std::endl; + // std::cerr << " apply_jl: var: " << var_sel << std::endl; if (mvmap_.has_series(var_tail)) { - std::cerr << " apply_jl: has series: " << var_sel << std::endl; + // std::cerr << " apply_jl: has series: " << var_sel << std::endl; auto val = mvmap_.get_as_variant(var_tail, loc); if (val.has_value()) { - std::cerr << " apply_jl: val has value" << std::endl; + // std::cerr << " apply_jl: val has value" << std::endl; std::visit( [&submission_data, &loc, &var_str](auto&& v) { submission_data[var_str] = boost::json::value(v); - std::cerr << " apply_jl: submission_data[" << var_str - << "] = " << v << " at loc " << loc << "." - << std::endl; + // std::cerr << " apply_jl: submission_data[" << var_str + // << "] = " << v << " at loc " << loc << "." + // << std::endl; }, *val); } else { @@ -64,11 +79,13 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression, std::cerr << " apply_jl: no series for " << var_sel << std::endl; } } - std::cerr << " apply_jl: submission_data: " << submission_data - << std::endl; - jsonlogic::any_value res = rule.apply(jsonlogic::json_accessor(submission_data)); - std::cerr << " apply_jl: res: " << res << std::endl; - return truthy(res); + // std::cerr << " apply_jl: submission_data: " << submission_data + // << std::endl; + auto res = jlrule->apply(jsonlogic::json_accessor(submission_data)); + // jsonlogic::apply( + // *expression_rule, jsonlogic::data_accessor(submission_data)); + // std::cerr << " apply_jl: res: " << res << std::endl; + return jsonlogic::unpack_value(res); }; return apply_jl; @@ -79,59 +96,16 @@ std::vector where_nodes(const testgraph::testgraph& g, std::vector filtered_results; // boost::json::object exp2(expression); - std::cerr << " where: expression: " << expression << std::endl; - // auto [_a /*unused*/, vars, _b /*unused*/] = - // jsonlogic::translateNode(exp2["rule"]); - - // auto nodemap = g.nodemap(); - // boost::json::object submission_data{}; - // auto apply_jl = [&expression, &vars, &nodemap, - // &submission_data](testgraph::node_t key) { - // for (const auto& var : vars) { - // auto var_sel = selector(std::string(var)); - // if (!var_sel.headeq("node")) { - // std::cerr << "selector is not a node selector; skipping." << - // std::endl; continue; - // } - // auto var_tail = var_sel.tail().value(); - // std::string var_str = std::string(var_sel); - // std::cerr << " apply_jl: var: " << var_sel << std::endl; - // if (nodemap.has_series(var_tail)) { - // std::cerr << " apply_jl: has series: " << var_sel << std::endl; - // auto val = nodemap.get_as_variant(var_tail, key); - // if (val.has_value()) { - // std::cerr << " apply_jl: val has value" << std::endl; - // std::visit( - // [&submission_data, &key, &var_str](auto&& v) { - // submission_data[var_str] = boost::json::value(v); - // std::cerr << " apply_jl: submission_data[" << var_str - // << "] = " << v << " at key " << key << "." - // << std::endl; - // }, - // val.value()); - // } else { - // std::cerr << " apply_jl: no value for " << var_sel << std::endl; - // submission_data[var_str] = boost::json::value(); - // } - // } else { - // std::cerr << " apply_jl: no series for " << var_sel << std::endl; - // } - // } - - // jsonlogic::any_expr res = - // jsonlogic::apply(expression["rule"], submission_data); - // std::cerr << " apply_jl: res: " << res << std::endl; - // return jsonlogic::unpack_value(res); - // }; + // std::cerr << " where: expression: " << expression << std::endl; auto nodemap = g.nodemap(); boost::json::object submission_data; auto apply_jl = parse_where_expression(nodemap, expression, submission_data); - nodemap.for_all([&filtered_results, &apply_jl, &nodemap, &expression]( - const auto& key, const auto& loc) { - std::cerr << " where for_all key: " << key << std::endl; + nodemap.for_all([&filtered_results, &apply_jl, &nodemap, + &expression](const auto &key, const auto &loc) { + // std::cerr << " where for_all key: " << key << std::endl; if (apply_jl(loc)) { - std::cerr << " where: applied!" << std::endl; + // std::cerr << " where: applied!" << std::endl; filtered_results.push_back(key); } }); diff --git a/test/TestSet/remove_if.cpp b/test/TestSet/remove_if.cpp index 15122c7..2b86284 100644 --- a/test/TestSet/remove_if.cpp +++ b/test/TestSet/remove_if.cpp @@ -3,10 +3,8 @@ // // SPDX-License-Identifier: MIT -#include #include #include -#include #include #include diff --git a/test/requirements.txt b/test/requirements.txt index bcb9aac..e13a1ff 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,2 +1,2 @@ -llnl-clippy >= 0.4 +llnl-clippy >= 0.4.2 pytest>=7,<8 \ No newline at end of file