Skip to content

Commit 1f56465

Browse files
committed
Update base for Update on "Replace pytree_assert with production pytree_check. Remove pytree_unreachable"
When handling untrusted input, it's not appropriate to use debug-only checks; we should be checking in prod as these are not programmer errors. pytree_unreachable was similarly being used for input validation. Differential Revision: [D68166301](https://our.internmc.facebook.com/intern/diff/D68166301/) [ghstack-poisoned]
1 parent 42a0908 commit 1f56465

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

extension/pytree/test/test_pytree.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@
1111
#include <gtest/gtest.h>
1212
#include <string>
1313

14+
using ::executorch::extension::pytree::arr;
1415
using ::executorch::extension::pytree::ContainerHandle;
1516
using ::executorch::extension::pytree::Key;
1617
using ::executorch::extension::pytree::Kind;
1718
using ::executorch::extension::pytree::unflatten;
1819

1920
using Leaf = int32_t;
2021

22+
TEST(PyTreeTest, ArrBasic) {
23+
arr<int> x(5);
24+
ASSERT_EQ(x.size(), 5);
25+
EXPECT_THROW(x.at(5), std::out_of_range);
26+
for (int ii = 0; ii < x.size(); ++ii) {
27+
x[ii] = 2 * ii;
28+
}
29+
int idx = 0;
30+
for (const auto item : x) {
31+
EXPECT_EQ(item, 2 * idx);
32+
++idx;
33+
}
34+
}
35+
2136
TEST(PyTreeTest, List) {
2237
Leaf items[2] = {11, 12};
2338
std::string spec = "L2#1#1($,$)";

0 commit comments

Comments
 (0)