Skip to content

Commit

Permalink
Fix #1933: Add dustmite arguments: --compiler-text, --linker-text, --…
Browse files Browse the repository at this point in the history
…program-text
  • Loading branch information
nordlow committed Feb 14, 2024
1 parent 5f4ea8e commit 26c4852
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
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 @@ class DustmiteCommand : PackageBuildCommand {
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 @@ class DustmiteCommand : PackageBuildCommand {
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 @@ class DustmiteCommand : PackageBuildCommand {
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 @@ class DustmiteCommand : PackageBuildCommand {
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 @@ class DustmiteCommand : PackageBuildCommand {
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 @@ class DustmiteCommand : PackageBuildCommand {
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

0 comments on commit 26c4852

Please sign in to comment.