fix(tvix): Add missing break;s to BuildResult::FromProto
Add missing break statements to the big switch block in BuildResult::FromProto, and cover the whole thing with a rapidcheck round-trip test. Change-Id: I7a07ca398cc5f02ca4fd8e6256fd563c6f3aea9d Reviewed-on: https://cl.tvl.fyi/c/depot/+/2178 Tested-by: BuildkiteCI Reviewed-by: kanepyork <rikingcoding@gmail.com>
This commit is contained in:
parent
49024be056
commit
6f38ac6657
3 changed files with 72 additions and 0 deletions
13
third_party/nix/src/libstore/store-api.cc
vendored
13
third_party/nix/src/libstore/store-api.cc
vendored
|
@ -97,30 +97,43 @@ std::optional<BuildResult> BuildResult::FromProto(
|
||||||
switch (resp.status()) {
|
switch (resp.status()) {
|
||||||
case proto::BuildStatus::Built:
|
case proto::BuildStatus::Built:
|
||||||
result.status = BuildResult::Status::Built;
|
result.status = BuildResult::Status::Built;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::Substituted:
|
case proto::BuildStatus::Substituted:
|
||||||
result.status = BuildResult::Status::Substituted;
|
result.status = BuildResult::Status::Substituted;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::AlreadyValid:
|
case proto::BuildStatus::AlreadyValid:
|
||||||
result.status = BuildResult::Status::AlreadyValid;
|
result.status = BuildResult::Status::AlreadyValid;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::PermanentFailure:
|
case proto::BuildStatus::PermanentFailure:
|
||||||
result.status = BuildResult::Status::PermanentFailure;
|
result.status = BuildResult::Status::PermanentFailure;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::InputRejected:
|
case proto::BuildStatus::InputRejected:
|
||||||
result.status = BuildResult::Status::InputRejected;
|
result.status = BuildResult::Status::InputRejected;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::OutputRejected:
|
case proto::BuildStatus::OutputRejected:
|
||||||
result.status = BuildResult::Status::OutputRejected;
|
result.status = BuildResult::Status::OutputRejected;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::TransientFailure:
|
case proto::BuildStatus::TransientFailure:
|
||||||
result.status = BuildResult::Status::TransientFailure;
|
result.status = BuildResult::Status::TransientFailure;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::CachedFailure:
|
case proto::BuildStatus::CachedFailure:
|
||||||
result.status = BuildResult::Status::CachedFailure;
|
result.status = BuildResult::Status::CachedFailure;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::TimedOut:
|
case proto::BuildStatus::TimedOut:
|
||||||
result.status = BuildResult::Status::TimedOut;
|
result.status = BuildResult::Status::TimedOut;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::MiscFailure:
|
case proto::BuildStatus::MiscFailure:
|
||||||
result.status = BuildResult::Status::MiscFailure;
|
result.status = BuildResult::Status::MiscFailure;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::DependencyFailed:
|
case proto::BuildStatus::DependencyFailed:
|
||||||
result.status = BuildResult::Status::DependencyFailed;
|
result.status = BuildResult::Status::DependencyFailed;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::LogLimitExceeded:
|
case proto::BuildStatus::LogLimitExceeded:
|
||||||
result.status = BuildResult::Status::LogLimitExceeded;
|
result.status = BuildResult::Status::LogLimitExceeded;
|
||||||
|
break;
|
||||||
case proto::BuildStatus::NotDeterministic:
|
case proto::BuildStatus::NotDeterministic:
|
||||||
result.status = BuildResult::Status::NotDeterministic;
|
result.status = BuildResult::Status::NotDeterministic;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
10
third_party/nix/src/tests/CMakeLists.txt
vendored
10
third_party/nix/src/tests/CMakeLists.txt
vendored
|
@ -66,3 +66,13 @@ target_link_libraries(language-tests
|
||||||
)
|
)
|
||||||
|
|
||||||
gtest_discover_tests(language-tests)
|
gtest_discover_tests(language-tests)
|
||||||
|
|
||||||
|
add_executable(store-api-test store-api-test.cc)
|
||||||
|
target_link_libraries(store-api-test
|
||||||
|
nixstore
|
||||||
|
rapidcheck
|
||||||
|
rapidcheck_gtest
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_discover_tests(store-api-test)
|
||||||
|
|
49
third_party/nix/src/tests/store-api-test.cc
vendored
Normal file
49
third_party/nix/src/tests/store-api-test.cc
vendored
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include "libstore/store-api.hh"
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <rapidcheck/Assertions.h>
|
||||||
|
#include <rapidcheck/Gen.h>
|
||||||
|
#include <rapidcheck/gtest.h>
|
||||||
|
|
||||||
|
#include "libproto/worker.pb.h"
|
||||||
|
|
||||||
|
namespace rc {
|
||||||
|
template <>
|
||||||
|
struct Arbitrary<nix::BuildResult::Status> {
|
||||||
|
static Gen<nix::BuildResult::Status> arbitrary() {
|
||||||
|
return gen::element(nix::BuildResult::Status::Built,
|
||||||
|
nix::BuildResult::Status::Substituted,
|
||||||
|
nix::BuildResult::Status::AlreadyValid,
|
||||||
|
nix::BuildResult::Status::PermanentFailure,
|
||||||
|
nix::BuildResult::Status::InputRejected,
|
||||||
|
nix::BuildResult::Status::OutputRejected,
|
||||||
|
nix::BuildResult::Status::TransientFailure,
|
||||||
|
nix::BuildResult::Status::CachedFailure,
|
||||||
|
nix::BuildResult::Status::TimedOut,
|
||||||
|
nix::BuildResult::Status::MiscFailure,
|
||||||
|
nix::BuildResult::Status::DependencyFailed,
|
||||||
|
nix::BuildResult::Status::LogLimitExceeded,
|
||||||
|
nix::BuildResult::Status::NotDeterministic);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace rc
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
class BuildResultTest : public ::testing::Test {};
|
||||||
|
|
||||||
|
RC_GTEST_PROP(BuildResultTest, StatusToFromProtoRoundTrip,
|
||||||
|
(BuildResult::Status && status)) {
|
||||||
|
BuildResult br;
|
||||||
|
br.status = status;
|
||||||
|
|
||||||
|
auto proto_status = br.status_to_proto();
|
||||||
|
nix::proto::BuildResult br_proto;
|
||||||
|
br_proto.set_status(proto_status);
|
||||||
|
|
||||||
|
auto result = BuildResult::FromProto(br_proto);
|
||||||
|
|
||||||
|
RC_ASSERT(result.value().status == status);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace nix
|
Loading…
Reference in a new issue