Skip to content

Commit 0d42ff1

Browse files
authored
Fix quoted paths, relative paths, and option order dependence (+ tests) (#80)
1 parent b6516b1 commit 0d42ff1

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,4 @@ jobs:
177177
CHANGELIST.md/*
178178
pluginval_Linux.zip/*
179179
pluginval_macOS.zip/*
180-
pluginval_Windows.zip/*
180+
pluginval_Windows.zip/*

Source/CommandLine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,13 @@ bool shouldPerformCommandLine (const String& commandLine)
462462
//==============================================================================
463463
std::pair<juce::String, PluginTests::Options> parseCommandLine (const juce::ArgumentList& args)
464464
{
465-
auto fileOrID = args.getValueForOption ("--validate");
465+
auto fileOrID = getOptionValue (args, "--validate", "", "Expected a plugin path for the --validate option").toString();
466466

467+
// in the case of a path (vs. ID), grab the full path
468+
// getCurrentWorkingDirectory is needed to handle relative paths
469+
// It preserves absolute paths and first checks for ~ on Mac/Windows
467470
if (fileOrID.contains ("~") || fileOrID.contains ("."))
468-
fileOrID = juce::File (fileOrID).getFullPathName();
471+
fileOrID = File::getCurrentWorkingDirectory().getChildFile(fileOrID).getFullPathName();
469472

470473
PluginTests::Options options;
471474
options.strictnessLevel = getStrictnessLevel (args);
@@ -482,7 +485,7 @@ std::pair<juce::String, PluginTests::Options> parseCommandLine (const juce::Argu
482485
options.blockSizes = getBlockSizes (args);
483486
options.vst3Validator = getOptionValue (args, "--vst3validator", "", "Expected a path for the --vst3validator option");
484487

485-
return { args.arguments.getLast().text, options };
488+
return { fileOrID, options };
486489
}
487490

488491
std::pair<juce::String, PluginTests::Options> parseCommandLine (const String& cmd)

Source/CommandLineTests.cpp

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct CommandLineTests : public UnitTest
2222

2323
void runTest() override
2424
{
25-
25+
2626
beginTest ("Merge environment variables");
2727
{
2828
StringPairArray envVars;
@@ -61,13 +61,84 @@ struct CommandLineTests : public UnitTest
6161

6262
beginTest ("Command line parser");
6363
{
64-
ArgumentList args ({}, "--strictness-level 7 --random-seed 1234 --timeout-ms 20000 --repeat 11 --data-file <path_to_file> --output-dir <path_to_dir>");
64+
ArgumentList args ({}, "--strictness-level 7 --random-seed 1234 --timeout-ms 20000 --repeat 11 --data-file /path/to/file --output-dir /path/to/dir --validate /path/to/plugin");
6565
expectEquals (getStrictnessLevel (args), 7);
6666
expectEquals (getRandomSeed (args), (int64) 1234);
6767
expectEquals (getTimeout (args), (int64) 20000);
6868
expectEquals (getNumRepeats (args), 11);
69-
expectEquals (getOptionValue (args, "--data-file", {}, "Missing data-file path argument!").toString(), String ("<path_to_file>"));
70-
expectEquals (getOptionValue (args, "--output-dir", {}, "Missing output-dir path argument!").toString(), String ("<path_to_dir>"));
69+
expectEquals (getOptionValue (args, "--data-file", {}, "Missing data-file path argument!").toString(), String ("/path/to/file"));
70+
expectEquals (getOptionValue (args, "--output-dir", {}, "Missing output-dir path argument!").toString(), String ("/path/to/dir"));
71+
expectEquals (getOptionValue (args, "--validate", {}, "Missing validate argument!").toString(), String ("/path/to/plugin"));
72+
}
73+
74+
beginTest ("Handles an absolute path to the plugin");
75+
{
76+
const auto homeDir = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
77+
const auto commandLineString = "--validate " + homeDir + "/path/to/MyPlugin";
78+
const auto args = createCommandLineArgs (commandLineString);
79+
expectEquals (parseCommandLine (args).first, homeDir + "/path/to/MyPlugin");
80+
}
81+
82+
beginTest ("Handles a quoted absolute path to the plugin");
83+
{
84+
const auto homeDir = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
85+
const auto pathToQuote = homeDir + "/path/to/MyPlugin";
86+
const auto commandLineString = "--validate " + pathToQuote.quoted();
87+
const auto args = createCommandLineArgs (commandLineString);
88+
expectEquals (parseCommandLine (args).first, homeDir + "/path/to/MyPlugin");
89+
}
90+
91+
beginTest ("Handles a relative path");
92+
{
93+
const auto currentDir = File::getCurrentWorkingDirectory();
94+
const auto args = createCommandLineArgs ("--validate MyPlugin.vst3");
95+
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("MyPlugin.vst3").getFullPathName());
96+
}
97+
98+
beginTest ("Handles a quoted relative path with spaces to the plugin");
99+
{
100+
const auto currentDir = File::getCurrentWorkingDirectory();
101+
const auto args = createCommandLineArgs (R"(--validate "My Plugin.vst3")");
102+
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("My Plugin.vst3").getFullPathName());
103+
}
104+
105+
#if !JUCE_WINDOWS
106+
107+
beginTest ("Handles a relative path with ./ to the plugin");
108+
{
109+
const auto currentDir = File::getCurrentWorkingDirectory().getFullPathName();
110+
const auto commandLineString = "--validate ./path/to/MyPlugin";
111+
const auto args = createCommandLineArgs(commandLineString);
112+
expectEquals (parseCommandLine (args).first, currentDir + "/path/to/MyPlugin");
113+
}
114+
115+
beginTest ("Handles a home directory relative path to the plugin");
116+
{
117+
const auto commandLineString = "--validate ~/path/to/MyPlugin";
118+
const auto args = createCommandLineArgs(commandLineString);
119+
expectEquals (parseCommandLine (args).first, File::getSpecialLocation (File::userHomeDirectory).getFullPathName() + "/path/to/MyPlugin");
120+
}
121+
122+
beginTest ("Handles quoted strings, spaces, and home directory relative path to the plugin");
123+
{
124+
const auto commandLineString = R"(--data-file "~/path/to/My File" --output-dir "~/path/to/My Directory" --validate "~/path/to/My Plugin")";
125+
const auto args = createCommandLineArgs(commandLineString);
126+
expectEquals (parseCommandLine (args).first, File::getSpecialLocation (File::userHomeDirectory).getFullPathName() + "/path/to/My Plugin");
127+
}
128+
#endif
129+
130+
beginTest ("Implicit validate with a relative path");
131+
{
132+
const auto currentDir = File::getCurrentWorkingDirectory();
133+
const auto args = createCommandLineArgs ("MyPlugin.vst3");
134+
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("MyPlugin.vst3").getFullPathName());
135+
}
136+
137+
beginTest ("Doesn't alter component IDs");
138+
{
139+
const auto commandLineString = "--validate MyPluginID";
140+
const auto args = createCommandLineArgs(commandLineString);
141+
expectEquals (parseCommandLine (args).first, String ("MyPluginID"));
71142
}
72143

73144
beginTest ("Command line random");
@@ -82,6 +153,14 @@ struct CommandLineTests : public UnitTest
82153
expect (temp.getFile().create());
83154
expect (shouldPerformCommandLine (temp.getFile().getFullPathName()));
84155
}
156+
157+
beginTest ("Allows for other options after explicit --validate");
158+
{
159+
const auto currentDir = File::getCurrentWorkingDirectory();
160+
const auto args = createCommandLineArgs ("--validate MyPlugin.vst3 --randomise");
161+
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("MyPlugin.vst3").getFullPathName());
162+
expect (parseCommandLine(args).second.randomiseTestOrder);
163+
}
85164
}
86165
};
87166

Source/Validator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum class ValidationType
3232

3333
//==============================================================================
3434
/**
35-
A single, asyncronouse validation pass for a specific plugin.
35+
A single, asynchronous validation pass for a specific plugin.
3636
*/
3737
class ValidationPass
3838
{

0 commit comments

Comments
 (0)