Stop passing null function properties in testing

This allows us to assert that our functions are not null.
This commit is contained in:
ridiculousfish 2021-10-21 13:34:46 -07:00
parent 59b63f3aab
commit d904cc4964
2 changed files with 19 additions and 4 deletions

View file

@ -3132,9 +3132,25 @@ static void test_autoload() {
autoload_tester_t::run_test();
}
// Construct function properties for testing.
static std::shared_ptr<function_properties_t> make_test_func_props() {
auto ret = std::make_shared<function_properties_t>();
ret->parsed_source = parse_source(L"function stuff; end", parse_flag_none, nullptr);
assert(ret->parsed_source && "Failed to parse");
for (const auto &node : ret->parsed_source->ast) {
if (const auto *s = node.try_as<ast::block_statement_t>()) {
ret->func_node = s;
break;
}
}
assert(ret->func_node && "Unable to find block statement");
return ret;
}
static void test_complete() {
say(L"Testing complete");
auto func_props = make_test_func_props();
struct test_complete_vars_t : environment_t {
wcstring_list_t get_names(int flags) const override {
UNUSED(flags);
@ -3255,9 +3271,7 @@ static void test_complete() {
#endif
// Add a function and test completing it in various ways.
// Note we're depending on function_add not complaining when given missing parsed_source /
// body_node.
function_add(L"scuttlebutt", {}, nullptr, {});
function_add(L"scuttlebutt", {}, func_props, {});
// Complete a function name.
completions = do_complete(L"echo (scuttlebut", {});
@ -3347,7 +3361,7 @@ static void test_complete() {
// Test abbreviations.
auto &pvars = parser_t::principal_parser().vars();
function_add(L"testabbrsonetwothreefour", {}, nullptr, {});
function_add(L"testabbrsonetwothreefour", {}, func_props, {});
int ret = pvars.set_one(L"_fish_abbr_testabbrsonetwothreezero", ENV_LOCAL, L"expansion");
completions = complete(L"testabbrsonetwothree", {}, parser->context());
do_test(ret == 0);

View file

@ -154,6 +154,7 @@ function_info_t::function_info_t(function_properties_ref_t props, wcstring desc,
void function_add(wcstring name, wcstring description, function_properties_ref_t props,
const wchar_t *filename) {
ASSERT_IS_MAIN_THREAD();
assert(props && "Null props");
auto funcset = function_set.acquire();
// Historical check. TODO: rationalize this.