From 26c4852046b41f0e6d852544f14df81c8a8a3329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Nordl=C3=B6w?= Date: Wed, 14 Feb 2024 10:14:35 +0100 Subject: [PATCH] Fix #1933: Add dustmite arguments: --compiler-text, --linker-text, --program-text --- scripts/fish-completion/dub.fish | 3 +++ scripts/zsh-completion/_dub | 3 +++ source/dub/commandline.d | 25 ++++++++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/scripts/fish-completion/dub.fish b/scripts/fish-completion/dub.fish index 1ed8fb801..4206856bd 100644 --- a/scripts/fish-completion/dub.fish +++ b/scripts/fish-completion/dub.fish @@ -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 diff --git a/scripts/zsh-completion/_dub b/scripts/zsh-completion/_dub index 4550cd807..9a7e74ad8 100644 --- a/scripts/zsh-completion/_dub +++ b/scripts/zsh-completion/_dub @@ -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]' ) diff --git a/source/dub/commandline.d b/source/dub/commandline.d index f84d70dd3..2f940af86 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -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; @@ -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"]); @@ -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); try dub.generateProject("build", gensettings); catch (DustmiteMismatchException) { logInfoNoTag("Dustmite test doesn't match."); @@ -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"; @@ -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; @@ -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; + } + 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); logInfo("%s", output); throw new DustmiteMismatchException; }