mirror of
https://github.com/audacity/linuxdeploy.git
synced 2026-07-06 17:00:07 -05:00
Reduce amount of implicit behavior in desktop file parser
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// local headers
|
||||
#include "linuxdeploy/core/desktopfile/exceptions.h"
|
||||
#include "linuxdeploy/core/desktopfile/desktopfile.h"
|
||||
#include "linuxdeploy/core/log.h"
|
||||
#include "desktopfilereader.h"
|
||||
@@ -34,10 +35,15 @@ namespace linuxdeploy {
|
||||
DesktopFile::DesktopFile() : d(std::make_shared<PrivateData>()) {}
|
||||
|
||||
DesktopFile::DesktopFile(const bf::path& path) : DesktopFile() {
|
||||
if (bf::exists(path)) {
|
||||
// will throw exceptions in case of issues
|
||||
read(path);
|
||||
// if the file doesn't exist, an exception shall be thrown
|
||||
// otherwise, a user cannot know for sure whether a file was actually read (would need to check this
|
||||
// manually beforehand
|
||||
if (!bf::exists(path)) {
|
||||
throw IOError("Could not find file " + path.string());
|
||||
}
|
||||
|
||||
// will throw exceptions in case of issues
|
||||
read(path);
|
||||
};
|
||||
|
||||
DesktopFile::DesktopFile(std::istream& is) : DesktopFile() {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
// local headers
|
||||
#include "linuxdeploy/core/desktopfile/desktopfile.h"
|
||||
#include "linuxdeploy/core/desktopfile/exceptions.h"
|
||||
#include "../../src/core/desktopfile/desktopfilereader.h"
|
||||
|
||||
using boost::bad_lexical_cast;
|
||||
@@ -66,8 +67,7 @@ TEST_F(DesktopFileFixture, testDefaultConstructor) {
|
||||
}
|
||||
|
||||
TEST_F(DesktopFileFixture, testPathConstructor) {
|
||||
DesktopFile nonExistingPath("/a/b/c/d/e/f/g/h/1/2/3/4/5/6/7/8");
|
||||
EXPECT_TRUE(nonExistingPath.isEmpty());
|
||||
ASSERT_THROW(DesktopFile nonExistingPath("/a/b/c/d/e/f/g/h/1/2/3/4/5/6/7/8"), IOError);
|
||||
|
||||
DesktopFile emptyFile("/dev/null");
|
||||
EXPECT_TRUE(emptyFile.isEmpty());
|
||||
|
||||
Reference in New Issue
Block a user