Skip to content

Commit

Permalink
Fix tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Oct 15, 2015
1 parent 988501e commit 046927e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Start desktoptest on specified directories:

Example using cmd on Windows (KDE installed):

dub run desktopfile:desktoptest -- "%SYSTEMDRIVE%\ProgramData\KDE\share\applications" "%APPDATA%\.kde\share"
set KDE_SHARE="%SYSTEMDRIVE%\ProgramData\KDE\share"
dub run desktopfile:desktoptest -- %KDE_SHARE%\applications %KDE_SHARE%\templates" %KDE_SHARE%\desktop-directories %KDE_SHARE%\autostart


2 changes: 1 addition & 1 deletion examples/desktoptest/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main(string[] args)
writefln("Using directories: %-(%s, %)", desktopDirs);

foreach(dir; desktopDirs.filter!(s => s.exists && s.isDir())) {
foreach(entry; dir.dirEntries(SpanMode.depth).filter!(a => a.isFile() && a.extension == ".desktop")) {
foreach(entry; dir.dirEntries(SpanMode.depth).filter!(a => a.isFile() && (a.extension == ".desktop" || a.extension == ".directory"))) {
debug writeln(entry);
try {
new DesktopFile(entry);
Expand Down
26 changes: 20 additions & 6 deletions source/desktopfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -645,16 +645,30 @@ public:
string contents =
`[Desktop Entry]
Name=Program
Type=Application`;
Type=Directory`;

auto appPaths = ["/usr/share/applications", "/usr/local/share/applications"];
auto df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, "/usr/share/applications/de/example.desktop");
assert(df.id(appPaths) == "de-example.desktop");
string[] appPaths;
string filePath, nestedFilePath, wrongFilePath;

df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, "/usr/local/share/applications/example.desktop");
version(Windows) {
appPaths = [`C:\ProgramData\KDE\share\applications`, `C:\Users\username\.kde\share\applications`];
filePath = `C:\ProgramData\KDE\share\applications\example.desktop`;
nestedFilePath = `C:\ProgramData\KDE\share\applications\kde\example.desktop`;
wrongFilePath = `C:\ProgramData\desktop\example.desktop`;
} else {
appPaths = ["/usr/share/applications", "/usr/local/share/applications"];
filePath = "/usr/share/applications/example.desktop";
nestedFilePath = "/usr/share/applications/kde/example.desktop";
wrongFilePath = "/etc/desktop/example.desktop";
}

auto df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, nestedFilePath);
assert(df.id(appPaths) == "kde-example.desktop");

df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, filePath);
assert(df.id(appPaths) == "example.desktop");

df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, "/etc/desktop/example.desktop");
df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, wrongFilePath);
assert(df.id(appPaths).empty);
}

Expand Down

0 comments on commit 046927e

Please sign in to comment.