-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2051 "Running unittests from dub single file packages fails"
Performing test command dub imports every source file as module to build the project excluding the main source file. But this excluding may fail and in this case dub try to import the main source file as module. Single file package building fails because the main source file does not belong to any import path. Now both the current file and the main source file paths are compared in relative form to prevent importing the main source file as module.
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
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
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,3 @@ | ||
Fix #2051 "Running unit tests from DUB single file packages fails" | ||
|
||
Now dub is capable run test command in single mode like: `dub test --single yoursinglefile.d` |
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
76 changes: 76 additions & 0 deletions
76
test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d
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,76 @@ | ||
/+ dub.sdl: | ||
name "issue_2051_running_unittests_from_dub_single_file_packages_fails" | ||
+/ | ||
|
||
import std.algorithm : any; | ||
import std.conv : text; | ||
import std.file : tempDir; | ||
import std.stdio : File, writeln; | ||
import std.string : lineSplitter; | ||
import std.path : buildPath; | ||
import std.process : environment, executeShell; | ||
|
||
auto executeCommand(string command) | ||
{ | ||
import std.exception : enforce; | ||
|
||
auto dub = executeShell(command); | ||
writeln("--- dub output:"); | ||
foreach(line; dub.output.lineSplitter) | ||
writeln("\t", line); | ||
writeln("--- end of dub output"); | ||
|
||
enforce(dub.status == 0, "couldn't build the project, see above"); | ||
|
||
return dub.output; | ||
} | ||
|
||
/// check dub output to determine rebuild has not been triggered | ||
auto checkUnittestsResult(string output) | ||
{ | ||
if (output.lineSplitter.any!(a=> a == "All unit tests have been run successfully.")) | ||
{ | ||
writeln("\nOk. Unittest passed."); | ||
return 0; | ||
} | ||
else | ||
{ | ||
writeln("\nError. Unittests failed."); | ||
return 1; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
auto dub = environment.get("DUB"); | ||
if (!dub.length) | ||
dub = buildPath(".", "bin", "dub"); | ||
|
||
string filename; | ||
// create test_project | ||
{ | ||
filename = tempDir.buildPath("issue_2051.d"); | ||
auto f = File(filename, "w"); | ||
f.write( | ||
`#!/usr/bin/env dub | ||
/+ dub.sdl: | ||
name "issue2051" | ||
+/ | ||
version(unittest) {} | ||
else void main() | ||
{ | ||
} | ||
unittest | ||
{ | ||
auto input = [1721]; | ||
assert(input[0] == 1721); | ||
} | ||
` ); | ||
} | ||
|
||
return text(dub, " test --single ", filename) | ||
.executeCommand | ||
.checkUnittestsResult; | ||
} |