Loading base/expected_test.cpp +15 −15 Original line number Diff line number Diff line Loading @@ -408,11 +408,11 @@ TEST(Expected, testDereference) { TEST(Expected, testTest) { exp_int e = 10; EXPECT_TRUE(e); EXPECT_TRUE(e.ok()); EXPECT_TRUE(e.has_value()); exp_int e2 = unexpected(10); EXPECT_FALSE(e2); EXPECT_FALSE(e2.ok()); EXPECT_FALSE(e2.has_value()); } Loading Loading @@ -571,11 +571,11 @@ TEST(Expected, testDivideExample) { } }; EXPECT_FALSE(divide(10, 0)); EXPECT_FALSE(divide(10, 0).ok()); EXPECT_EQ("divide by zero", divide(10, 0).error().message); EXPECT_EQ(-1, divide(10, 0).error().cause); EXPECT_TRUE(divide(10, 3)); EXPECT_TRUE(divide(10, 3).ok()); EXPECT_EQ(QR(3, 1), *divide(10, 3)); } Loading @@ -589,7 +589,7 @@ TEST(Expected, testPair) { }; auto r = test(true); EXPECT_TRUE(r); EXPECT_TRUE(r.ok()); EXPECT_EQ("yes", r->first); } Loading @@ -603,9 +603,9 @@ TEST(Expected, testVoid) { }; auto r = test(true); EXPECT_TRUE(r); EXPECT_TRUE(r.ok()); r = test(false); EXPECT_FALSE(r); EXPECT_FALSE(r.ok()); EXPECT_EQ(10, r.error()); } Loading Loading @@ -754,7 +754,7 @@ TEST(Expected, testNoCopyOnReturn) { ConstructorTracker::Reset(); auto result1 = test(""); ASSERT_TRUE(result1); ASSERT_TRUE(result1.ok()); EXPECT_EQ("literal string", result1->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -764,7 +764,7 @@ TEST(Expected, testNoCopyOnReturn) { ConstructorTracker::Reset(); auto result2 = test("test2"); ASSERT_TRUE(result2); ASSERT_TRUE(result2.ok()); EXPECT_EQ("test2test22", result2->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -774,7 +774,7 @@ TEST(Expected, testNoCopyOnReturn) { ConstructorTracker::Reset(); auto result3 = test("test3"); ASSERT_TRUE(result3); ASSERT_TRUE(result3.ok()); EXPECT_EQ("test3 test3", result3->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -786,22 +786,22 @@ TEST(Expected, testNoCopyOnReturn) { TEST(Expected, testNested) { expected<exp_string, std::string> e = "hello"; EXPECT_TRUE(e.ok()); EXPECT_TRUE(e.has_value()); EXPECT_TRUE(e.value().has_value()); EXPECT_TRUE(e); EXPECT_TRUE(*e); EXPECT_TRUE(e->ok()); EXPECT_EQ("hello", e.value().value()); expected<exp_string, std::string> e2 = unexpected("world"); EXPECT_FALSE(e2.has_value()); EXPECT_FALSE(e2); EXPECT_FALSE(e2.ok()); EXPECT_EQ("world", e2.error()); expected<exp_string, std::string> e3 = exp_string(unexpected("world")); EXPECT_TRUE(e3.has_value()); EXPECT_FALSE(e3.value().has_value()); EXPECT_TRUE(e3); EXPECT_FALSE(*e3); EXPECT_TRUE(e3.ok()); EXPECT_FALSE(e3->ok()); EXPECT_EQ("world", e3.value().error()); } Loading base/result_test.cpp +29 −29 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ namespace base { TEST(result, result_accessors) { Result<std::string> result = "success"; ASSERT_TRUE(result); ASSERT_RESULT_OK(result); ASSERT_TRUE(result.has_value()); EXPECT_EQ("success", *result); Loading @@ -40,7 +40,7 @@ TEST(result, result_accessors) { } TEST(result, result_accessors_rvalue) { ASSERT_TRUE(Result<std::string>("success")); ASSERT_TRUE(Result<std::string>("success").ok()); ASSERT_TRUE(Result<std::string>("success").has_value()); EXPECT_EQ("success", *Result<std::string>("success")); Loading @@ -51,12 +51,12 @@ TEST(result, result_accessors_rvalue) { TEST(result, result_void) { Result<void> ok = {}; EXPECT_TRUE(ok); EXPECT_RESULT_OK(ok); ok.value(); // should not crash ASSERT_DEATH(ok.error(), ""); Result<void> fail = Error() << "failure" << 1; EXPECT_FALSE(fail); EXPECT_FALSE(fail.ok()); EXPECT_EQ("failure1", fail.error().message()); EXPECT_EQ(0, fail.error().code()); EXPECT_TRUE(ok != fail); Loading @@ -66,8 +66,8 @@ TEST(result, result_void) { if (ok) return {}; else return Error() << "failure" << 1; }; EXPECT_TRUE(test(true)); EXPECT_FALSE(test(false)); EXPECT_TRUE(test(true).ok()); EXPECT_FALSE(test(false).ok()); test(true).value(); // should not crash ASSERT_DEATH(test(true).error(), ""); ASSERT_DEATH(test(false).value(), ""); Loading @@ -76,7 +76,7 @@ TEST(result, result_void) { TEST(result, result_error) { Result<void> result = Error() << "failure" << 1; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(0, result.error().code()); Loading @@ -85,7 +85,7 @@ TEST(result, result_error) { TEST(result, result_error_empty) { Result<void> result = Error(); ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(0, result.error().code()); Loading @@ -100,7 +100,7 @@ TEST(result, result_error_rvalue) { // create is. auto MakeRvalueErrorResult = []() -> Result<void> { return Error() << "failure" << 1; }; ASSERT_FALSE(MakeRvalueErrorResult()); ASSERT_FALSE(MakeRvalueErrorResult().ok()); ASSERT_FALSE(MakeRvalueErrorResult().has_value()); EXPECT_EQ(0, MakeRvalueErrorResult().error().code()); Loading @@ -112,7 +112,7 @@ TEST(result, result_errno_error) { errno = test_errno; Result<void> result = ErrnoError() << "failure" << 1; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(test_errno, result.error().code()); Loading @@ -124,7 +124,7 @@ TEST(result, result_errno_error_no_text) { errno = test_errno; Result<void> result = ErrnoError(); ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(test_errno, result.error().code()); Loading @@ -135,12 +135,12 @@ TEST(result, result_error_from_other_result) { auto error_text = "test error"s; Result<void> result = Error() << error_text; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); Result<std::string> result2 = result.error(); ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); ASSERT_FALSE(result2.has_value()); EXPECT_EQ(0, result2.error().code()); Loading @@ -151,12 +151,12 @@ TEST(result, result_error_through_ostream) { auto error_text = "test error"s; Result<void> result = Error() << error_text; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); Result<std::string> result2 = Error() << result.error(); ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); ASSERT_FALSE(result2.has_value()); EXPECT_EQ(0, result2.error().code()); Loading @@ -171,12 +171,12 @@ TEST(result, result_errno_error_through_ostream) { errno = 0; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); Result<std::string> result2 = Error() << result.error(); ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); ASSERT_FALSE(result2.has_value()); EXPECT_EQ(test_errno, result2.error().code()); Loading @@ -186,7 +186,7 @@ TEST(result, result_errno_error_through_ostream) { TEST(result, constructor_forwarding) { auto result = Result<std::string>(std::in_place, 5, 'a'); ASSERT_TRUE(result); ASSERT_RESULT_OK(result); ASSERT_TRUE(result.has_value()); EXPECT_EQ("aaaaa", *result); Loading Loading @@ -254,7 +254,7 @@ TEST(result, no_copy_on_return) { // are called. auto result1 = ReturnConstructorTracker(""); ASSERT_TRUE(result1); ASSERT_RESULT_OK(result1); EXPECT_EQ("literal string", result1->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -263,7 +263,7 @@ TEST(result, no_copy_on_return) { EXPECT_EQ(0U, ConstructorTracker::move_assignment_called); auto result2 = ReturnConstructorTracker("test2"); ASSERT_TRUE(result2); ASSERT_RESULT_OK(result2); EXPECT_EQ("test2test22", result2->string); EXPECT_EQ(2U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -272,7 +272,7 @@ TEST(result, no_copy_on_return) { EXPECT_EQ(0U, ConstructorTracker::move_assignment_called); auto result3 = ReturnConstructorTracker("test3"); ASSERT_TRUE(result3); ASSERT_RESULT_OK(result3); EXPECT_EQ("test3 test3", result3->string); EXPECT_EQ(3U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -287,11 +287,11 @@ TEST(result, no_copy_on_return) { TEST(result, result_result_with_success) { auto return_result_result_with_success = []() -> Result<Result<void>> { return Result<void>(); }; auto result = return_result_result_with_success(); ASSERT_TRUE(result); ASSERT_TRUE(*result); ASSERT_RESULT_OK(result); ASSERT_RESULT_OK(*result); auto inner_result = result.value(); ASSERT_TRUE(inner_result); ASSERT_RESULT_OK(inner_result); } TEST(result, result_result_with_failure) { Loading @@ -299,8 +299,8 @@ TEST(result, result_result_with_failure) { return Result<void>(ResultError("failure string", 6)); }; auto result = return_result_result_with_error(); ASSERT_TRUE(result); ASSERT_FALSE(*result); ASSERT_RESULT_OK(result); ASSERT_FALSE(result->ok()); EXPECT_EQ("failure string", (*result).error().message()); EXPECT_EQ(6, (*result).error().code()); } Loading @@ -320,7 +320,7 @@ TEST(result, result_two_parameter_constructor_same_type) { }; auto result = return_test_struct(); ASSERT_TRUE(result); ASSERT_RESULT_OK(result); EXPECT_EQ(36, result->value_); } Loading @@ -344,13 +344,13 @@ TEST(result, preserve_errno) { errno = 1; int old_errno = errno; Result<int> result = Error() << "Failed" << SetErrnoToTwo<char>; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); EXPECT_EQ(old_errno, errno); errno = 1; old_errno = errno; Result<int> result2 = ErrnoError() << "Failed" << SetErrnoToTwo<char>; ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); EXPECT_EQ(old_errno, errno); EXPECT_EQ(old_errno, result2.error().code()); } Loading fs_mgr/libfs_avb/fs_avb.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -329,7 +329,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(const FstabEntry& fstab_entry, // or a string indicating multiple keys separated by ':'. std::vector<std::string> allowed_avb_keys; auto list_avb_keys_in_dir = ListFiles(fstab_entry.avb_keys); if (list_avb_keys_in_dir) { if (list_avb_keys_in_dir.ok()) { std::sort(list_avb_keys_in_dir->begin(), list_avb_keys_in_dir->end()); allowed_avb_keys = *list_avb_keys_in_dir; } else { Loading init/action.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ Result<void> RunBuiltinFunction(const BuiltinFunction& function, builtin_arguments.args[0] = args[0]; for (std::size_t i = 1; i < args.size(); ++i) { auto expanded_arg = ExpandProps(args[i]); if (!expanded_arg) { if (!expanded_arg.ok()) { return expanded_arg.error(); } builtin_arguments.args[i] = std::move(*expanded_arg); Loading @@ -59,7 +59,7 @@ Result<void> Command::InvokeFunc(Subcontext* subcontext) const { } auto expanded_args = subcontext->ExpandArgs(args_); if (!expanded_args) { if (!expanded_args.ok()) { return expanded_args.error(); } return RunBuiltinFunction(func_, *expanded_args, subcontext->context()); Loading @@ -75,7 +75,7 @@ Result<void> Command::CheckCommand() const { builtin_arguments.args[0] = args_[0]; for (size_t i = 1; i < args_.size(); ++i) { auto expanded_arg = ExpandProps(args_[i]); if (!expanded_arg) { if (!expanded_arg.ok()) { if (expanded_arg.error().message().find("doesn't exist while expanding") != std::string::npos) { // If we failed because we won't have a property, use an empty string, which is Loading Loading @@ -114,7 +114,7 @@ Result<void> Action::AddCommand(std::vector<std::string>&& args, int line) { } auto map_result = function_map_->Find(args); if (!map_result) { if (!map_result.ok()) { return Error() << map_result.error(); } Loading @@ -134,7 +134,7 @@ std::size_t Action::NumCommands() const { size_t Action::CheckAllCommands() const { size_t failures = 0; for (const auto& command : commands_) { if (auto result = command.CheckCommand(); !result) { if (auto result = command.CheckCommand(); !result.ok()) { LOG(ERROR) << "Command '" << command.BuildCommandString() << "' (" << filename_ << ":" << command.line() << ") failed: " << result.error(); ++failures; Loading Loading @@ -169,7 +169,7 @@ void Action::ExecuteCommand(const Command& command) const { LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << " (" << filename_ << ":" << command.line() << ") took " << duration.count() << "ms and " << (result ? "succeeded" : "failed: " + result.error().message()); << (result.ok() ? "succeeded" : "failed: " + result.error().message()); } } Loading init/action_parser.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -110,14 +110,14 @@ Result<void> ParseTriggers(const std::vector<std::string>& args, Subcontext* sub if (!args[i].compare(0, prop_str.length(), prop_str)) { if (auto result = ParsePropertyTrigger(args[i], subcontext, property_triggers); !result) { !result.ok()) { return result; } } else { if (!event_trigger->empty()) { return Error() << "multiple event triggers are not allowed"; } if (auto result = ValidateEventTrigger(args[i]); !result) { if (auto result = ValidateEventTrigger(args[i]); !result.ok()) { return result; } Loading Loading @@ -145,8 +145,9 @@ Result<void> ActionParser::ParseSection(std::vector<std::string>&& args, std::string event_trigger; std::map<std::string, std::string> property_triggers; if (auto result = ParseTriggers(triggers, action_subcontext, &event_trigger, &property_triggers); !result) { if (auto result = ParseTriggers(triggers, action_subcontext, &event_trigger, &property_triggers); !result.ok()) { return Error() << "ParseTriggers() failed: " << result.error(); } Loading Loading
base/expected_test.cpp +15 −15 Original line number Diff line number Diff line Loading @@ -408,11 +408,11 @@ TEST(Expected, testDereference) { TEST(Expected, testTest) { exp_int e = 10; EXPECT_TRUE(e); EXPECT_TRUE(e.ok()); EXPECT_TRUE(e.has_value()); exp_int e2 = unexpected(10); EXPECT_FALSE(e2); EXPECT_FALSE(e2.ok()); EXPECT_FALSE(e2.has_value()); } Loading Loading @@ -571,11 +571,11 @@ TEST(Expected, testDivideExample) { } }; EXPECT_FALSE(divide(10, 0)); EXPECT_FALSE(divide(10, 0).ok()); EXPECT_EQ("divide by zero", divide(10, 0).error().message); EXPECT_EQ(-1, divide(10, 0).error().cause); EXPECT_TRUE(divide(10, 3)); EXPECT_TRUE(divide(10, 3).ok()); EXPECT_EQ(QR(3, 1), *divide(10, 3)); } Loading @@ -589,7 +589,7 @@ TEST(Expected, testPair) { }; auto r = test(true); EXPECT_TRUE(r); EXPECT_TRUE(r.ok()); EXPECT_EQ("yes", r->first); } Loading @@ -603,9 +603,9 @@ TEST(Expected, testVoid) { }; auto r = test(true); EXPECT_TRUE(r); EXPECT_TRUE(r.ok()); r = test(false); EXPECT_FALSE(r); EXPECT_FALSE(r.ok()); EXPECT_EQ(10, r.error()); } Loading Loading @@ -754,7 +754,7 @@ TEST(Expected, testNoCopyOnReturn) { ConstructorTracker::Reset(); auto result1 = test(""); ASSERT_TRUE(result1); ASSERT_TRUE(result1.ok()); EXPECT_EQ("literal string", result1->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -764,7 +764,7 @@ TEST(Expected, testNoCopyOnReturn) { ConstructorTracker::Reset(); auto result2 = test("test2"); ASSERT_TRUE(result2); ASSERT_TRUE(result2.ok()); EXPECT_EQ("test2test22", result2->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -774,7 +774,7 @@ TEST(Expected, testNoCopyOnReturn) { ConstructorTracker::Reset(); auto result3 = test("test3"); ASSERT_TRUE(result3); ASSERT_TRUE(result3.ok()); EXPECT_EQ("test3 test3", result3->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -786,22 +786,22 @@ TEST(Expected, testNoCopyOnReturn) { TEST(Expected, testNested) { expected<exp_string, std::string> e = "hello"; EXPECT_TRUE(e.ok()); EXPECT_TRUE(e.has_value()); EXPECT_TRUE(e.value().has_value()); EXPECT_TRUE(e); EXPECT_TRUE(*e); EXPECT_TRUE(e->ok()); EXPECT_EQ("hello", e.value().value()); expected<exp_string, std::string> e2 = unexpected("world"); EXPECT_FALSE(e2.has_value()); EXPECT_FALSE(e2); EXPECT_FALSE(e2.ok()); EXPECT_EQ("world", e2.error()); expected<exp_string, std::string> e3 = exp_string(unexpected("world")); EXPECT_TRUE(e3.has_value()); EXPECT_FALSE(e3.value().has_value()); EXPECT_TRUE(e3); EXPECT_FALSE(*e3); EXPECT_TRUE(e3.ok()); EXPECT_FALSE(e3->ok()); EXPECT_EQ("world", e3.value().error()); } Loading
base/result_test.cpp +29 −29 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ namespace base { TEST(result, result_accessors) { Result<std::string> result = "success"; ASSERT_TRUE(result); ASSERT_RESULT_OK(result); ASSERT_TRUE(result.has_value()); EXPECT_EQ("success", *result); Loading @@ -40,7 +40,7 @@ TEST(result, result_accessors) { } TEST(result, result_accessors_rvalue) { ASSERT_TRUE(Result<std::string>("success")); ASSERT_TRUE(Result<std::string>("success").ok()); ASSERT_TRUE(Result<std::string>("success").has_value()); EXPECT_EQ("success", *Result<std::string>("success")); Loading @@ -51,12 +51,12 @@ TEST(result, result_accessors_rvalue) { TEST(result, result_void) { Result<void> ok = {}; EXPECT_TRUE(ok); EXPECT_RESULT_OK(ok); ok.value(); // should not crash ASSERT_DEATH(ok.error(), ""); Result<void> fail = Error() << "failure" << 1; EXPECT_FALSE(fail); EXPECT_FALSE(fail.ok()); EXPECT_EQ("failure1", fail.error().message()); EXPECT_EQ(0, fail.error().code()); EXPECT_TRUE(ok != fail); Loading @@ -66,8 +66,8 @@ TEST(result, result_void) { if (ok) return {}; else return Error() << "failure" << 1; }; EXPECT_TRUE(test(true)); EXPECT_FALSE(test(false)); EXPECT_TRUE(test(true).ok()); EXPECT_FALSE(test(false).ok()); test(true).value(); // should not crash ASSERT_DEATH(test(true).error(), ""); ASSERT_DEATH(test(false).value(), ""); Loading @@ -76,7 +76,7 @@ TEST(result, result_void) { TEST(result, result_error) { Result<void> result = Error() << "failure" << 1; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(0, result.error().code()); Loading @@ -85,7 +85,7 @@ TEST(result, result_error) { TEST(result, result_error_empty) { Result<void> result = Error(); ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(0, result.error().code()); Loading @@ -100,7 +100,7 @@ TEST(result, result_error_rvalue) { // create is. auto MakeRvalueErrorResult = []() -> Result<void> { return Error() << "failure" << 1; }; ASSERT_FALSE(MakeRvalueErrorResult()); ASSERT_FALSE(MakeRvalueErrorResult().ok()); ASSERT_FALSE(MakeRvalueErrorResult().has_value()); EXPECT_EQ(0, MakeRvalueErrorResult().error().code()); Loading @@ -112,7 +112,7 @@ TEST(result, result_errno_error) { errno = test_errno; Result<void> result = ErrnoError() << "failure" << 1; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(test_errno, result.error().code()); Loading @@ -124,7 +124,7 @@ TEST(result, result_errno_error_no_text) { errno = test_errno; Result<void> result = ErrnoError(); ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); EXPECT_EQ(test_errno, result.error().code()); Loading @@ -135,12 +135,12 @@ TEST(result, result_error_from_other_result) { auto error_text = "test error"s; Result<void> result = Error() << error_text; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); Result<std::string> result2 = result.error(); ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); ASSERT_FALSE(result2.has_value()); EXPECT_EQ(0, result2.error().code()); Loading @@ -151,12 +151,12 @@ TEST(result, result_error_through_ostream) { auto error_text = "test error"s; Result<void> result = Error() << error_text; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); Result<std::string> result2 = Error() << result.error(); ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); ASSERT_FALSE(result2.has_value()); EXPECT_EQ(0, result2.error().code()); Loading @@ -171,12 +171,12 @@ TEST(result, result_errno_error_through_ostream) { errno = 0; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); ASSERT_FALSE(result.has_value()); Result<std::string> result2 = Error() << result.error(); ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); ASSERT_FALSE(result2.has_value()); EXPECT_EQ(test_errno, result2.error().code()); Loading @@ -186,7 +186,7 @@ TEST(result, result_errno_error_through_ostream) { TEST(result, constructor_forwarding) { auto result = Result<std::string>(std::in_place, 5, 'a'); ASSERT_TRUE(result); ASSERT_RESULT_OK(result); ASSERT_TRUE(result.has_value()); EXPECT_EQ("aaaaa", *result); Loading Loading @@ -254,7 +254,7 @@ TEST(result, no_copy_on_return) { // are called. auto result1 = ReturnConstructorTracker(""); ASSERT_TRUE(result1); ASSERT_RESULT_OK(result1); EXPECT_EQ("literal string", result1->string); EXPECT_EQ(1U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -263,7 +263,7 @@ TEST(result, no_copy_on_return) { EXPECT_EQ(0U, ConstructorTracker::move_assignment_called); auto result2 = ReturnConstructorTracker("test2"); ASSERT_TRUE(result2); ASSERT_RESULT_OK(result2); EXPECT_EQ("test2test22", result2->string); EXPECT_EQ(2U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -272,7 +272,7 @@ TEST(result, no_copy_on_return) { EXPECT_EQ(0U, ConstructorTracker::move_assignment_called); auto result3 = ReturnConstructorTracker("test3"); ASSERT_TRUE(result3); ASSERT_RESULT_OK(result3); EXPECT_EQ("test3 test3", result3->string); EXPECT_EQ(3U, ConstructorTracker::constructor_called); EXPECT_EQ(0U, ConstructorTracker::copy_constructor_called); Loading @@ -287,11 +287,11 @@ TEST(result, no_copy_on_return) { TEST(result, result_result_with_success) { auto return_result_result_with_success = []() -> Result<Result<void>> { return Result<void>(); }; auto result = return_result_result_with_success(); ASSERT_TRUE(result); ASSERT_TRUE(*result); ASSERT_RESULT_OK(result); ASSERT_RESULT_OK(*result); auto inner_result = result.value(); ASSERT_TRUE(inner_result); ASSERT_RESULT_OK(inner_result); } TEST(result, result_result_with_failure) { Loading @@ -299,8 +299,8 @@ TEST(result, result_result_with_failure) { return Result<void>(ResultError("failure string", 6)); }; auto result = return_result_result_with_error(); ASSERT_TRUE(result); ASSERT_FALSE(*result); ASSERT_RESULT_OK(result); ASSERT_FALSE(result->ok()); EXPECT_EQ("failure string", (*result).error().message()); EXPECT_EQ(6, (*result).error().code()); } Loading @@ -320,7 +320,7 @@ TEST(result, result_two_parameter_constructor_same_type) { }; auto result = return_test_struct(); ASSERT_TRUE(result); ASSERT_RESULT_OK(result); EXPECT_EQ(36, result->value_); } Loading @@ -344,13 +344,13 @@ TEST(result, preserve_errno) { errno = 1; int old_errno = errno; Result<int> result = Error() << "Failed" << SetErrnoToTwo<char>; ASSERT_FALSE(result); ASSERT_FALSE(result.ok()); EXPECT_EQ(old_errno, errno); errno = 1; old_errno = errno; Result<int> result2 = ErrnoError() << "Failed" << SetErrnoToTwo<char>; ASSERT_FALSE(result2); ASSERT_FALSE(result2.ok()); EXPECT_EQ(old_errno, errno); EXPECT_EQ(old_errno, result2.error().code()); } Loading
fs_mgr/libfs_avb/fs_avb.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -329,7 +329,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(const FstabEntry& fstab_entry, // or a string indicating multiple keys separated by ':'. std::vector<std::string> allowed_avb_keys; auto list_avb_keys_in_dir = ListFiles(fstab_entry.avb_keys); if (list_avb_keys_in_dir) { if (list_avb_keys_in_dir.ok()) { std::sort(list_avb_keys_in_dir->begin(), list_avb_keys_in_dir->end()); allowed_avb_keys = *list_avb_keys_in_dir; } else { Loading
init/action.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ Result<void> RunBuiltinFunction(const BuiltinFunction& function, builtin_arguments.args[0] = args[0]; for (std::size_t i = 1; i < args.size(); ++i) { auto expanded_arg = ExpandProps(args[i]); if (!expanded_arg) { if (!expanded_arg.ok()) { return expanded_arg.error(); } builtin_arguments.args[i] = std::move(*expanded_arg); Loading @@ -59,7 +59,7 @@ Result<void> Command::InvokeFunc(Subcontext* subcontext) const { } auto expanded_args = subcontext->ExpandArgs(args_); if (!expanded_args) { if (!expanded_args.ok()) { return expanded_args.error(); } return RunBuiltinFunction(func_, *expanded_args, subcontext->context()); Loading @@ -75,7 +75,7 @@ Result<void> Command::CheckCommand() const { builtin_arguments.args[0] = args_[0]; for (size_t i = 1; i < args_.size(); ++i) { auto expanded_arg = ExpandProps(args_[i]); if (!expanded_arg) { if (!expanded_arg.ok()) { if (expanded_arg.error().message().find("doesn't exist while expanding") != std::string::npos) { // If we failed because we won't have a property, use an empty string, which is Loading Loading @@ -114,7 +114,7 @@ Result<void> Action::AddCommand(std::vector<std::string>&& args, int line) { } auto map_result = function_map_->Find(args); if (!map_result) { if (!map_result.ok()) { return Error() << map_result.error(); } Loading @@ -134,7 +134,7 @@ std::size_t Action::NumCommands() const { size_t Action::CheckAllCommands() const { size_t failures = 0; for (const auto& command : commands_) { if (auto result = command.CheckCommand(); !result) { if (auto result = command.CheckCommand(); !result.ok()) { LOG(ERROR) << "Command '" << command.BuildCommandString() << "' (" << filename_ << ":" << command.line() << ") failed: " << result.error(); ++failures; Loading Loading @@ -169,7 +169,7 @@ void Action::ExecuteCommand(const Command& command) const { LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << " (" << filename_ << ":" << command.line() << ") took " << duration.count() << "ms and " << (result ? "succeeded" : "failed: " + result.error().message()); << (result.ok() ? "succeeded" : "failed: " + result.error().message()); } } Loading
init/action_parser.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -110,14 +110,14 @@ Result<void> ParseTriggers(const std::vector<std::string>& args, Subcontext* sub if (!args[i].compare(0, prop_str.length(), prop_str)) { if (auto result = ParsePropertyTrigger(args[i], subcontext, property_triggers); !result) { !result.ok()) { return result; } } else { if (!event_trigger->empty()) { return Error() << "multiple event triggers are not allowed"; } if (auto result = ValidateEventTrigger(args[i]); !result) { if (auto result = ValidateEventTrigger(args[i]); !result.ok()) { return result; } Loading Loading @@ -145,8 +145,9 @@ Result<void> ActionParser::ParseSection(std::vector<std::string>&& args, std::string event_trigger; std::map<std::string, std::string> property_triggers; if (auto result = ParseTriggers(triggers, action_subcontext, &event_trigger, &property_triggers); !result) { if (auto result = ParseTriggers(triggers, action_subcontext, &event_trigger, &property_triggers); !result.ok()) { return Error() << "ParseTriggers() failed: " << result.error(); } Loading