Skip to content

Commit 4a70ffe

Browse files
committed
Add failing unit test for accessing member of null object
1 parent 52179d8 commit 4a70ffe

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/test_module.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@ class TestMoreDerivedType : public TestDerivedType
5151

5252
std::shared_ptr<TestBaseType> derived_type_factory()
5353
{
54-
return std::shared_ptr<TestBaseType>(new TestDerivedType());
54+
return std::make_shared<TestDerivedType>();
5555
}
5656

5757
std::shared_ptr<TestBaseType> more_derived_type_factory()
5858
{
59-
return std::shared_ptr<TestBaseType>(new TestMoreDerivedType());
59+
return std::make_shared<TestBaseType>();
60+
}
61+
62+
std::shared_ptr<TestBaseType> null_factory()
63+
{
64+
return std::shared_ptr<TestBaseType>();
6065
}
6166

6267
std::string hello_world()
@@ -111,6 +116,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
111116

112117
m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory");
113118
m->add(chaiscript::fun(&more_derived_type_factory), "more_derived_type_factory");
119+
m->add(chaiscript::fun(&null_factory), "null_factory");
114120

115121
m->add(chaiscript::fun(&TestDerivedType::func), "func");
116122

unittests/null_object_access.chai

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load_module("test_module")
2+
3+
auto o = null_factory();
4+
5+
try {
6+
o.func();
7+
} catch (e) {
8+
exit(0);
9+
}
10+
11+
assert_true(false);
12+
13+

0 commit comments

Comments
 (0)