Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1933: Add dustmite arguments: --compiler-text, --linker-text, --program-text #2854

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/fish-completion/dub.fish
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ end

for cmd in dustmite
complete -c dub -n "contains '$cmd' (commandline -poc)" -l compiler-status -x -d "Expected compiler status code"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l compiler-text -x -d "Compiler output (sub) string"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l compiler-regex -x -d "Compiler output regular expression"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l linker-status -x -d "Expected linker status code"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l linker-text -x -d "Linker output (sub) string"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l linker-regex -x -d "Linker output regular expression"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l program-status -x -d "Expected program status code"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l program-text -x -d "Program output (sub) string"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l program-regex -x -d "Program output regular expression"
complete -c dub -n "contains '$cmd' (commandline -poc)" -l test-package -x -d "Perform a test run"
end
Expand Down
3 changes: 3 additions & 0 deletions scripts/zsh-completion/_dub
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,13 @@ _dub_dustmite() {
local localArgs=(
':target directory:_directories'
'--compiler-status=[The expected status code of the compiler run]:status code: '
'--compiler-text=[A (sub) string used to match against the compiler output]:regex: '
'--compiler-regex=[A regular expression used to match against the compiler output]:regex: '
'--linker-status=[The expected status code of the linker run]:status code: '
'--linker-text=[A (sub) string used to match against the linker output]:text: '
'--linker-regex=[A regular expression used to match against the linker output]:regex: '
'--program-status=[The expected status code of the built executable]:status code: '
'--program-text=[A (sub) string used to match against the program output]:text: '
'--program-regex=[A regular expression used to match against the program output]:regex: '
'--[End of dub arguments, the following will be sent to the program]'
)
Expand Down
25 changes: 20 additions & 5 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -2686,8 +2686,11 @@
int m_compilerStatusCode = int.min;
int m_linkerStatusCode = int.min;
int m_programStatusCode = int.min;
string m_compilerText;
string m_compilerRegex;
string m_linkerText;
string m_linkerRegex;
string m_programText;
string m_programRegex;
string m_testPackage;
bool m_noRedirect;
Expand All @@ -2714,10 +2717,13 @@
override void prepare(scope CommandArgs args)
{
args.getopt("compiler-status", &m_compilerStatusCode, ["The expected status code of the compiler run"]);
args.getopt("compiler-text", &m_compilerText, ["A (sub) string used to match against the compiler output"]);
args.getopt("compiler-regex", &m_compilerRegex, ["A regular expression used to match against the compiler output"]);
args.getopt("linker-status", &m_linkerStatusCode, ["The expected status code of the linker run"]);
args.getopt("linker-text", &m_linkerText, ["A (sub) string used to match against the linker output"]);
args.getopt("linker-regex", &m_linkerRegex, ["A regular expression used to match against the linker output"]);
args.getopt("program-status", &m_programStatusCode, ["The expected status code of the built executable"]);
args.getopt("program-text", &m_programText, ["A (sub) string used to match against the program output"]);
args.getopt("program-regex", &m_programRegex, ["A regular expression used to match against the program output"]);
args.getopt("test-package", &m_testPackage, ["Perform a test run - usually only used internally"]);
args.getopt("combined", &this.baseSettings.combined, ["Builds multiple packages with one compiler run"]);
Expand Down Expand Up @@ -2755,9 +2761,9 @@
gensettings.run = m_programStatusCode != int.min || m_programRegex.length;
gensettings.runArgs = app_args;
gensettings.force = true;
gensettings.compileCallback = check(m_compilerStatusCode, m_compilerRegex);
gensettings.linkCallback = check(m_linkerStatusCode, m_linkerRegex);
gensettings.runCallback = check(m_programStatusCode, m_programRegex);
gensettings.compileCallback = check(m_compilerStatusCode, m_compilerText, m_compilerRegex);
gensettings.linkCallback = check(m_linkerStatusCode, m_linkerText, m_linkerRegex);
gensettings.runCallback = check(m_programStatusCode, m_programText, m_programRegex);

Check warning on line 2766 in source/dub/commandline.d

View check run for this annotation

Codecov / codecov/patch

source/dub/commandline.d#L2764-L2766

Added lines #L2764 - L2766 were not covered by tests
try dub.generateProject("build", gensettings);
catch (DustmiteMismatchException) {
logInfoNoTag("Dustmite test doesn't match.");
Expand Down Expand Up @@ -2849,10 +2855,13 @@
if (m_compilerName.length) testcmd.formattedWrite(" \"--compiler=%s\"", m_compilerName);
if (m_arch.length) testcmd.formattedWrite(" --arch=%s", m_arch);
if (m_compilerStatusCode != int.min) testcmd.formattedWrite(" --compiler-status=%s", m_compilerStatusCode);
if (m_compilerText.length) testcmd.formattedWrite(" \"--compiler-text=%s\"", m_compilerText);
if (m_compilerRegex.length) testcmd.formattedWrite(" \"--compiler-regex=%s\"", m_compilerRegex);
if (m_linkerStatusCode != int.min) testcmd.formattedWrite(" --linker-status=%s", m_linkerStatusCode);
if (m_linkerText.length) testcmd.formattedWrite(" \"--linker-text=%s\"", m_linkerText);
if (m_linkerRegex.length) testcmd.formattedWrite(" \"--linker-regex=%s\"", m_linkerRegex);
if (m_programStatusCode != int.min) testcmd.formattedWrite(" --program-status=%s", m_programStatusCode);
if (m_programText.length) testcmd.formattedWrite(" \"--program-text=%s\"", m_programText);
if (m_programRegex.length) testcmd.formattedWrite(" \"--program-regex=%s\"", m_programRegex);
if (this.baseSettings.combined) testcmd ~= " --combined";

Expand All @@ -2875,7 +2884,7 @@
return 0;
}

void delegate(int, string) check(int code_match, string regex_match)
void delegate(int, string) check(int code_match, string string_match, string regex_match)
{
return (code, output) {
import std.encoding;
Expand All @@ -2888,8 +2897,14 @@
throw new DustmiteMismatchException;
}

if (string_match.length > 0 && !output.sanitize.canFind(string_match)) {
logInfo("Output doesn't contain (sub) string %s:", string_match);
logInfo("%s", output);
throw new DustmiteMismatchException;

Check warning on line 2903 in source/dub/commandline.d

View check run for this annotation

Codecov / codecov/patch

source/dub/commandline.d#L2900-L2903

Added lines #L2900 - L2903 were not covered by tests
}

if (regex_match.length > 0 && !match(output.sanitize, regex_match)) {
logInfo("Output doesn't match regex:");
logInfo("Output doesn't match regex %s:", regex_match);

Check warning on line 2907 in source/dub/commandline.d

View check run for this annotation

Codecov / codecov/patch

source/dub/commandline.d#L2907

Added line #L2907 was not covered by tests
logInfo("%s", output);
throw new DustmiteMismatchException;
}
Expand Down
Loading