Skip to content

Commit

Permalink
Improve handling of 'srcdir' environment variable
Browse files Browse the repository at this point in the history
Throw a more meaningful exception if the srcdir variable is not set, rather
than a construction error from inside std::string.
  • Loading branch information
Matthew Mott committed Mar 13, 2019
1 parent 7fa01ec commit 98e01bb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions radiant/test/VFSFixture.h
Expand Up @@ -12,16 +12,24 @@ struct VFSFixture
vfs::VirtualFileSystem::ExtensionSet pakExtensions;
vfs::SearchPaths searchPaths;

// Get the srcdir environment variable (set by Automake)
std::string srcdir() const
{
const char* envVal = getenv("srcdir");
if (envVal)
return std::string(envVal);
else
throw std::runtime_error("srcdir not set");
}

VFSFixture()
{
// Setup the output stream
GlobalOutputStream().setStream(std::cout);

// Configure search paths and extensions
pakExtensions.insert("pk4");
searchPaths.insertIfNotExists(
std::string(getenv("srcdir")) + "/test/data/vfs_root"
);
searchPaths.insertIfNotExists(srcdir() + "/test/data/vfs_root");

// Initialise the VFS
fs.initialise(searchPaths, pakExtensions);
Expand Down

0 comments on commit 98e01bb

Please sign in to comment.