-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor InstallPaths API and comments a little. #4341
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,14 @@ | |
#include "tools/cpp/runfiles/runfiles.h" | ||
|
||
namespace Carbon { | ||
|
||
class InstallPathsTestPeer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (not for this PR, maybe for a follow-up) Is "test peer" a well established term? I couldn't find it when searching, and it was new to me. And the term "peer" is specific enough that I somewhat expect it to have a fairly specific meaning. If its not that established, I'm still perfectly happy with the pattern itself to allow testing -- but maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, left to my own devices, I'd just make InstallPathsTest itself the friend... (I would mainly expect peers/helpers for something we use in multiple places, not just once) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I'm merging, expecting we'll come up with some unified solution for InstallPathsTestPeer, TypedNodesTestPeer, and InstTestHelper) |
||
public: | ||
static auto GetPrefix(const InstallPaths& paths) -> llvm::StringRef { | ||
return paths.prefix_; | ||
} | ||
}; | ||
|
||
namespace { | ||
|
||
using ::bazel::tools::cpp::runfiles::Runfiles; | ||
|
@@ -37,17 +45,20 @@ class InstallPathsTest : public ::testing::Test { | |
// check that the path accessors point to the right kind of file or | ||
// directory. | ||
auto TestInstallPaths(const InstallPaths& paths) -> void { | ||
SCOPED_TRACE(llvm::formatv("Install prefix: '{0}'", paths.prefix())); | ||
auto prefix = InstallPathsTestPeer::GetPrefix(paths); | ||
|
||
SCOPED_TRACE(llvm::formatv("Install prefix: '{0}'", prefix)); | ||
|
||
// Grab a the prefix into a string to make it easier to use in the test. | ||
std::string prefix = paths.prefix().str(); | ||
EXPECT_TRUE(llvm::sys::fs::exists(prefix)); | ||
EXPECT_TRUE(llvm::sys::fs::is_directory(prefix)); | ||
|
||
// Now check that all the expected parts of the toolchain's install are in | ||
// fact found using the API. | ||
std::string driver_path = paths.driver(); | ||
ASSERT_THAT(driver_path, StartsWith(prefix)); | ||
llvm::SmallString<256> driver_path(prefix); | ||
// TODO: Adjust this to work equally well on Windows. | ||
llvm::sys::path::append(driver_path, llvm::sys::path::Style::posix, | ||
"bin/carbon"); | ||
EXPECT_TRUE(llvm::sys::fs::exists(driver_path)) << "path: " << driver_path; | ||
EXPECT_TRUE(llvm::sys::fs::can_execute(driver_path)) | ||
<< "path: " << driver_path; | ||
|
@@ -120,11 +131,11 @@ TEST_F(InstallPathsTest, BinaryRunfiles) { | |
TEST_F(InstallPathsTest, Errors) { | ||
auto paths = InstallPaths::Make("/foo/bar/baz"); | ||
EXPECT_THAT(paths.error(), Optional(HasSubstr("foo/bar/baz"))); | ||
EXPECT_THAT(paths.prefix(), Eq("")); | ||
EXPECT_THAT(InstallPathsTestPeer::GetPrefix(paths), Eq("")); | ||
|
||
paths = InstallPaths::MakeExeRelative("foo/bar/baz"); | ||
EXPECT_THAT(paths.error(), Optional(HasSubstr("foo/bar/baz"))); | ||
EXPECT_THAT(paths.prefix(), Eq("")); | ||
EXPECT_THAT(InstallPathsTestPeer::GetPrefix(paths), Eq("")); | ||
|
||
// Note that we can't test the runfiles code path from within a test because | ||
// it succeeds some of the time even with a bogus executable name. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
prefix_root
at the end looks a little suspicious to me. Is that right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use an explicit
prefix_root
for all the things installed in the package to keep them distinct from the code and other things in theinstall
package for managing an installation.