Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 436968b

Browse files
authored
Sbromberger/fix tests (#50)
* fix tests
1 parent b157b70 commit 436968b

File tree

8 files changed

+58
-84
lines changed

8 files changed

+58
-84
lines changed

.github/workflows/pr.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
- name: Install dependencies
1717
run: |
1818
python -m pip install --upgrade pip
19-
python -m pip install pytest git+https://github.com/llnl/clippy@master
19+
# python -m pip install pytest git+https://github.com/llnl/clippy@master
20+
python -m pip install pytest git+https://github.com/llnl/clippy@sbromberger/stream-stderr
2021
2122
2223
- name: Install Boost
@@ -47,14 +48,15 @@ jobs:
4748
# git clone https://github.com/LLNL/clippy-cpp --branch $GITHUB_HEAD_REF $TMPDIR
4849
4950
mkdir -p build
50-
cd build && cmake -DBOOST_ROOT=$BOOST_ROOT .. && make && cd ..
51+
cd build && cmake -DMODERN_CMAKE_BUILD_TESTING=ON -DBUILD_TESTING=ON -DBOOST_ROOT=$BOOST_ROOT .. && make && cd ..
5152
ls -l build/test
5253
BACKEND=$PWD/build/test
5354
echo "BACKEND=$BACKEND" >> $GITHUB_ENV
5455
5556
- name: Run Python test framework
5657
env:
57-
CLIPPY_BACKEND_PATH: ${{ env.BACKEND }}
58+
CLIPPY_BACKEND_PATH: ${{ github.workspace }}/build/test
59+
# CLIPPY_BACKEND_PATH: ${{ env.BACKEND }}
5860
run: |
59-
echo "backend = $BACKEND"
61+
echo "backend = $CLIPPY_BACKEND_PATH"
6062
pytest .

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
/.cache
33
/**/build
4+
/**/build.*
45
/.idea/
56
CMakeDoxyfile.in
67
CMakeDoxygenDefaults.cmake

test/TestBag/insert.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
#include "clippy/clippy.hpp"
77
#include <boost/json.hpp>
8-
#include <iostream>
9-
10-
namespace boostjsn = boost::json;
118

129
static const std::string class_name = "ClippyBag";
1310
static const std::string method_name = "insert";

test/TestBag/remove_if.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
//
44
// SPDX-License-Identifier: MIT
55

6-
#include <algorithm>
76
#include <boost/json.hpp>
87
#include <clippy/clippy.hpp>
9-
#include <iostream>
108
#include <jsonlogic/src.hpp>
119
#include <list>
1210
// #include <logic.hpp>
@@ -37,7 +35,8 @@ int main(int argc, char **argv) {
3735
auto apply_jl = [&jlrule](int value) {
3836
boostjsn::object data;
3937
data["value"] = value;
40-
return truthy(jlrule.apply(jsonlogic::json_accessor(std::move(data))));
38+
auto res = jlrule.apply(jsonlogic::json_accessor(data));
39+
return jsonlogic::unpack_value<bool>(res);
4140
};
4241

4342
the_bag.remove_if(apply_jl);

test/TestGraph/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
set(CMAKE_BUILD_TYPE Debug)
2+
3+
14
add_test(TestGraph __init__)
25
add_test(TestGraph __str__)
36
# add_test(TestGraph assign)

test/TestGraph/where.cpp

Lines changed: 45 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,67 @@
88
#include <vector>
99

1010
#include "clippy/selector.hpp"
11+
#include "jsonlogic/logic.hpp"
1112
#include "testgraph.hpp"
1213

1314
template <typename M>
1415
auto parse_where_expression(M& mvmap_, boost::json::object& expression,
1516
boost::json::object& submission_data) {
16-
std::cerr << " parse_where_expression: expression: " << expression
17-
<< std::endl;
17+
// std::cerr << " parse_where_expression: expression: " << expression
18+
// << std::endl;
1819
boost::json::object exp2(expression);
1920

21+
std::shared_ptr<jsonlogic::logic_rule> jlrule =
22+
std::make_shared<jsonlogic::logic_rule>(
23+
jsonlogic::create_logic(exp2["rule"]));
24+
// std::cerr << "past create_logic\n";
25+
auto vars = jlrule->variable_names();
2026
// boost::json::object submission_data{};
21-
std::vector<boost::json::string> vars;
27+
// jsonlogic::any_expr expression_rule_;
2228

2329
// we use expression_rule_ (and expression_rule; see below) in order to avoid
2430
// having to recompute this every time we call the lambda.
25-
jsonlogic::logic_rule jlrule = jsonlogic::create_logic(exp2["rule"]);
31+
// std::tie(expression_rule_, vars, std::ignore) =
32+
// jsonlogic::create_logic(exp2["rule"]);
2633

27-
std::cerr << "parse_where: # of vars: " << vars.size() << std::endl;
28-
for (const auto& var : vars) {
29-
std::cerr << " apply_jl var dump: var: " << var << std::endl;
30-
}
34+
// this works around a deficiency in C++ compilers where
35+
// unique pointers moved into a lambda cannot be moved into
36+
// an std::function.
37+
// jsonlogic::expr* rawexpr = expression_rule_.release();
38+
// std::shared_ptr<jsonlogic::expr> expression_rule{rawexpr};
39+
// std::shared_ptr<jsonlogic::logic_rule> jlshared{&jlrule};
3140

32-
auto apply_jl = [rule=std::move(jlrule), vars, &mvmap_,
41+
// std::cerr << "parse_where: # of vars: " << vars.size() << std::endl;
42+
// for (const auto& var : vars) {
43+
// std::cerr << " apply_jl var dump: var: " << var << std::endl;
44+
// }
45+
46+
auto apply_jl = [&expression, jlrule, &mvmap_,
3347
&submission_data](mvmap::locator loc) mutable {
34-
std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl;
48+
auto vars = jlrule->variable_names();
49+
// std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl;
3550
for (const auto& var : vars) {
36-
std::cerr << " apply_jl: var: " << var << std::endl;
51+
// std::cerr << " apply_jl: var: " << var << std::endl;
3752
auto var_sel = selector(std::string(var));
38-
std::cerr << " apply_jl: var_sel = " << var_sel << std::endl;
53+
// std::cerr << " apply_jl: var_sel = " << var_sel << std::endl;
3954
// if (!var_sel.headeq("node")) {
4055
// std::cerr << "selector is not a node selector; skipping." <<
4156
// std::endl; continue;
4257
// }
4358
auto var_tail = var_sel.tail().value();
4459
std::string var_str = std::string(var_sel);
45-
std::cerr << " apply_jl: var: " << var_sel << std::endl;
60+
// std::cerr << " apply_jl: var: " << var_sel << std::endl;
4661
if (mvmap_.has_series(var_tail)) {
47-
std::cerr << " apply_jl: has series: " << var_sel << std::endl;
62+
// std::cerr << " apply_jl: has series: " << var_sel << std::endl;
4863
auto val = mvmap_.get_as_variant(var_tail, loc);
4964
if (val.has_value()) {
50-
std::cerr << " apply_jl: val has value" << std::endl;
65+
// std::cerr << " apply_jl: val has value" << std::endl;
5166
std::visit(
5267
[&submission_data, &loc, &var_str](auto&& v) {
5368
submission_data[var_str] = boost::json::value(v);
54-
std::cerr << " apply_jl: submission_data[" << var_str
55-
<< "] = " << v << " at loc " << loc << "."
56-
<< std::endl;
69+
// std::cerr << " apply_jl: submission_data[" << var_str
70+
// << "] = " << v << " at loc " << loc << "."
71+
// << std::endl;
5772
},
5873
*val);
5974
} else {
@@ -64,11 +79,13 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression,
6479
std::cerr << " apply_jl: no series for " << var_sel << std::endl;
6580
}
6681
}
67-
std::cerr << " apply_jl: submission_data: " << submission_data
68-
<< std::endl;
69-
jsonlogic::any_value res = rule.apply(jsonlogic::json_accessor(submission_data));
70-
std::cerr << " apply_jl: res: " << res << std::endl;
71-
return truthy(res);
82+
// std::cerr << " apply_jl: submission_data: " << submission_data
83+
// << std::endl;
84+
auto res = jlrule->apply(jsonlogic::json_accessor(submission_data));
85+
// jsonlogic::apply(
86+
// *expression_rule, jsonlogic::data_accessor(submission_data));
87+
// std::cerr << " apply_jl: res: " << res << std::endl;
88+
return jsonlogic::unpack_value<bool>(res);
7289
};
7390

7491
return apply_jl;
@@ -79,59 +96,16 @@ std::vector<testgraph::node_t> where_nodes(const testgraph::testgraph& g,
7996
std::vector<testgraph::node_t> filtered_results;
8097
// boost::json::object exp2(expression);
8198

82-
std::cerr << " where: expression: " << expression << std::endl;
83-
// auto [_a /*unused*/, vars, _b /*unused*/] =
84-
// jsonlogic::translateNode(exp2["rule"]);
85-
86-
// auto nodemap = g.nodemap();
87-
// boost::json::object submission_data{};
88-
// auto apply_jl = [&expression, &vars, &nodemap,
89-
// &submission_data](testgraph::node_t key) {
90-
// for (const auto& var : vars) {
91-
// auto var_sel = selector(std::string(var));
92-
// if (!var_sel.headeq("node")) {
93-
// std::cerr << "selector is not a node selector; skipping." <<
94-
// std::endl; continue;
95-
// }
96-
// auto var_tail = var_sel.tail().value();
97-
// std::string var_str = std::string(var_sel);
98-
// std::cerr << " apply_jl: var: " << var_sel << std::endl;
99-
// if (nodemap.has_series(var_tail)) {
100-
// std::cerr << " apply_jl: has series: " << var_sel << std::endl;
101-
// auto val = nodemap.get_as_variant(var_tail, key);
102-
// if (val.has_value()) {
103-
// std::cerr << " apply_jl: val has value" << std::endl;
104-
// std::visit(
105-
// [&submission_data, &key, &var_str](auto&& v) {
106-
// submission_data[var_str] = boost::json::value(v);
107-
// std::cerr << " apply_jl: submission_data[" << var_str
108-
// << "] = " << v << " at key " << key << "."
109-
// << std::endl;
110-
// },
111-
// val.value());
112-
// } else {
113-
// std::cerr << " apply_jl: no value for " << var_sel << std::endl;
114-
// submission_data[var_str] = boost::json::value();
115-
// }
116-
// } else {
117-
// std::cerr << " apply_jl: no series for " << var_sel << std::endl;
118-
// }
119-
// }
120-
121-
// jsonlogic::any_expr res =
122-
// jsonlogic::apply(expression["rule"], submission_data);
123-
// std::cerr << " apply_jl: res: " << res << std::endl;
124-
// return jsonlogic::unpack_value<bool>(res);
125-
// };
99+
// std::cerr << " where: expression: " << expression << std::endl;
126100

127101
auto nodemap = g.nodemap();
128102
boost::json::object submission_data;
129103
auto apply_jl = parse_where_expression(nodemap, expression, submission_data);
130-
nodemap.for_all([&filtered_results, &apply_jl, &nodemap, &expression](
131-
const auto& key, const auto& loc) {
132-
std::cerr << " where for_all key: " << key << std::endl;
104+
nodemap.for_all([&filtered_results, &apply_jl, &nodemap,
105+
&expression](const auto &key, const auto &loc) {
106+
// std::cerr << " where for_all key: " << key << std::endl;
133107
if (apply_jl(loc)) {
134-
std::cerr << " where: applied!" << std::endl;
108+
// std::cerr << " where: applied!" << std::endl;
135109
filtered_results.push_back(key);
136110
}
137111
});

test/TestSet/remove_if.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
//
44
// SPDX-License-Identifier: MIT
55

6-
#include <algorithm>
76
#include <boost/json.hpp>
87
#include <clippy/clippy.hpp>
9-
#include <iostream>
108
#include <jsonlogic/src.hpp>
119
#include <set>
1210

test/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
llnl-clippy >= 0.4
1+
llnl-clippy >= 0.4.2
22
pytest>=7,<8

0 commit comments

Comments
 (0)