forked from mongodb/genny
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TIG-1209: Add findRepoRoot to assist with loading test fixtures (mong…
- Loading branch information
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This is a "dummy" file used by `findRepoRoot` to find the "root" of the Genny | ||
repository by successively looking up the directory tree from cwd. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ find_package( | |
1.68 | ||
REQUIRED | ||
COMPONENTS | ||
filesystem | ||
log_setup | ||
log | ||
program_options | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2019-present MongoDB Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef HEADER_00E808D9_C909_4A88_99A5_C0B5E8596E84_INCLUDED | ||
#define HEADER_00E808D9_C909_4A88_99A5_C0B5E8596E84_INCLUDED | ||
|
||
#include <string> | ||
|
||
namespace genny { | ||
|
||
/** | ||
* @return the path to the Genny repository's root directory by looking 'up' the directory tree. | ||
* @throws invalid_argument if not inside the genny repository | ||
*/ | ||
std::string findRepoRoot(); | ||
|
||
} // namespace genny | ||
|
||
#endif // HEADER_00E808D9_C909_4A88_99A5_C0B5E8596E84_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2019-present MongoDB Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <testlib/findRepoRoot.hpp> | ||
|
||
#include <boost/filesystem.hpp> | ||
#include <sstream> | ||
|
||
namespace genny { | ||
|
||
namespace { | ||
|
||
constexpr auto ROOT_FILE = ".genny-root"; | ||
|
||
} // namespace | ||
|
||
|
||
// | ||
// Note this function doesn't have any automated testing. Be careful when changing. | ||
// | ||
std::string findRepoRoot() { | ||
using namespace boost::filesystem; | ||
|
||
auto fileSystemRoot = path("/"); | ||
|
||
auto curr = current_path(); | ||
const auto start = curr; | ||
|
||
while (!exists(curr / ROOT_FILE)) { | ||
curr = curr / ".."; | ||
if (curr == fileSystemRoot) { | ||
std::stringstream msg; | ||
msg << "Cannot find '" << ROOT_FILE << "' in '" << start << "'"; | ||
throw std::invalid_argument(msg.str()); | ||
} | ||
} | ||
|
||
return curr.string(); | ||
} | ||
|
||
|
||
} // namespace genny |