Add failing unit test for accessing member of null object
This commit is contained in:
parent
52179d8333
commit
4a70ffe599
@ -51,12 +51,17 @@ class TestMoreDerivedType : public TestDerivedType
|
|||||||
|
|
||||||
std::shared_ptr<TestBaseType> derived_type_factory()
|
std::shared_ptr<TestBaseType> derived_type_factory()
|
||||||
{
|
{
|
||||||
return std::shared_ptr<TestBaseType>(new TestDerivedType());
|
return std::make_shared<TestDerivedType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TestBaseType> more_derived_type_factory()
|
std::shared_ptr<TestBaseType> more_derived_type_factory()
|
||||||
{
|
{
|
||||||
return std::shared_ptr<TestBaseType>(new TestMoreDerivedType());
|
return std::make_shared<TestBaseType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<TestBaseType> null_factory()
|
||||||
|
{
|
||||||
|
return std::shared_ptr<TestBaseType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string hello_world()
|
std::string hello_world()
|
||||||
@ -111,6 +116,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
|
|||||||
|
|
||||||
m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory");
|
m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory");
|
||||||
m->add(chaiscript::fun(&more_derived_type_factory), "more_derived_type_factory");
|
m->add(chaiscript::fun(&more_derived_type_factory), "more_derived_type_factory");
|
||||||
|
m->add(chaiscript::fun(&null_factory), "null_factory");
|
||||||
|
|
||||||
m->add(chaiscript::fun(&TestDerivedType::func), "func");
|
m->add(chaiscript::fun(&TestDerivedType::func), "func");
|
||||||
|
|
||||||
|
13
unittests/null_object_access.chai
Normal file
13
unittests/null_object_access.chai
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
load_module("test_module")
|
||||||
|
|
||||||
|
auto o = null_factory();
|
||||||
|
|
||||||
|
try {
|
||||||
|
o.func();
|
||||||
|
} catch (e) {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_true(false);
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user