Skip to content

Commit

Permalink
Fix quoted paths, relative paths, and option order dependence (+ test…
Browse files Browse the repository at this point in the history
…s) (#80)
  • Loading branch information
sudara authored Jul 22, 2022
1 parent b6516b1 commit 0d42ff1
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ jobs:
CHANGELIST.md/*
pluginval_Linux.zip/*
pluginval_macOS.zip/*
pluginval_Windows.zip/*
pluginval_Windows.zip/*
9 changes: 6 additions & 3 deletions Source/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,13 @@ bool shouldPerformCommandLine (const String& commandLine)
//==============================================================================
std::pair<juce::String, PluginTests::Options> parseCommandLine (const juce::ArgumentList& args)
{
auto fileOrID = args.getValueForOption ("--validate");
auto fileOrID = getOptionValue (args, "--validate", "", "Expected a plugin path for the --validate option").toString();

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

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

return { args.arguments.getLast().text, options };
return { fileOrID, options };
}

std::pair<juce::String, PluginTests::Options> parseCommandLine (const String& cmd)
Expand Down
87 changes: 83 additions & 4 deletions Source/CommandLineTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct CommandLineTests : public UnitTest

void runTest() override
{

beginTest ("Merge environment variables");
{
StringPairArray envVars;
Expand Down Expand Up @@ -61,13 +61,84 @@ struct CommandLineTests : public UnitTest

beginTest ("Command line parser");
{
ArgumentList args ({}, "--strictness-level 7 --random-seed 1234 --timeout-ms 20000 --repeat 11 --data-file <path_to_file> --output-dir <path_to_dir>");
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");
expectEquals (getStrictnessLevel (args), 7);
expectEquals (getRandomSeed (args), (int64) 1234);
expectEquals (getTimeout (args), (int64) 20000);
expectEquals (getNumRepeats (args), 11);
expectEquals (getOptionValue (args, "--data-file", {}, "Missing data-file path argument!").toString(), String ("<path_to_file>"));
expectEquals (getOptionValue (args, "--output-dir", {}, "Missing output-dir path argument!").toString(), String ("<path_to_dir>"));
expectEquals (getOptionValue (args, "--data-file", {}, "Missing data-file path argument!").toString(), String ("/path/to/file"));
expectEquals (getOptionValue (args, "--output-dir", {}, "Missing output-dir path argument!").toString(), String ("/path/to/dir"));
expectEquals (getOptionValue (args, "--validate", {}, "Missing validate argument!").toString(), String ("/path/to/plugin"));
}

beginTest ("Handles an absolute path to the plugin");
{
const auto homeDir = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
const auto commandLineString = "--validate " + homeDir + "/path/to/MyPlugin";
const auto args = createCommandLineArgs (commandLineString);
expectEquals (parseCommandLine (args).first, homeDir + "/path/to/MyPlugin");
}

beginTest ("Handles a quoted absolute path to the plugin");
{
const auto homeDir = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
const auto pathToQuote = homeDir + "/path/to/MyPlugin";
const auto commandLineString = "--validate " + pathToQuote.quoted();
const auto args = createCommandLineArgs (commandLineString);
expectEquals (parseCommandLine (args).first, homeDir + "/path/to/MyPlugin");
}

beginTest ("Handles a relative path");
{
const auto currentDir = File::getCurrentWorkingDirectory();
const auto args = createCommandLineArgs ("--validate MyPlugin.vst3");
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("MyPlugin.vst3").getFullPathName());
}

beginTest ("Handles a quoted relative path with spaces to the plugin");
{
const auto currentDir = File::getCurrentWorkingDirectory();
const auto args = createCommandLineArgs (R"(--validate "My Plugin.vst3")");
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("My Plugin.vst3").getFullPathName());
}

#if !JUCE_WINDOWS

beginTest ("Handles a relative path with ./ to the plugin");
{
const auto currentDir = File::getCurrentWorkingDirectory().getFullPathName();
const auto commandLineString = "--validate ./path/to/MyPlugin";
const auto args = createCommandLineArgs(commandLineString);
expectEquals (parseCommandLine (args).first, currentDir + "/path/to/MyPlugin");
}

beginTest ("Handles a home directory relative path to the plugin");
{
const auto commandLineString = "--validate ~/path/to/MyPlugin";
const auto args = createCommandLineArgs(commandLineString);
expectEquals (parseCommandLine (args).first, File::getSpecialLocation (File::userHomeDirectory).getFullPathName() + "/path/to/MyPlugin");
}

beginTest ("Handles quoted strings, spaces, and home directory relative path to the plugin");
{
const auto commandLineString = R"(--data-file "~/path/to/My File" --output-dir "~/path/to/My Directory" --validate "~/path/to/My Plugin")";
const auto args = createCommandLineArgs(commandLineString);
expectEquals (parseCommandLine (args).first, File::getSpecialLocation (File::userHomeDirectory).getFullPathName() + "/path/to/My Plugin");
}
#endif

beginTest ("Implicit validate with a relative path");
{
const auto currentDir = File::getCurrentWorkingDirectory();
const auto args = createCommandLineArgs ("MyPlugin.vst3");
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("MyPlugin.vst3").getFullPathName());
}

beginTest ("Doesn't alter component IDs");
{
const auto commandLineString = "--validate MyPluginID";
const auto args = createCommandLineArgs(commandLineString);
expectEquals (parseCommandLine (args).first, String ("MyPluginID"));
}

beginTest ("Command line random");
Expand All @@ -82,6 +153,14 @@ struct CommandLineTests : public UnitTest
expect (temp.getFile().create());
expect (shouldPerformCommandLine (temp.getFile().getFullPathName()));
}

beginTest ("Allows for other options after explicit --validate");
{
const auto currentDir = File::getCurrentWorkingDirectory();
const auto args = createCommandLineArgs ("--validate MyPlugin.vst3 --randomise");
expectEquals (parseCommandLine (args).first, currentDir.getChildFile ("MyPlugin.vst3").getFullPathName());
expect (parseCommandLine(args).second.randomiseTestOrder);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion Source/Validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum class ValidationType

//==============================================================================
/**
A single, asyncronouse validation pass for a specific plugin.
A single, asynchronous validation pass for a specific plugin.
*/
class ValidationPass
{
Expand Down

0 comments on commit 0d42ff1

Please sign in to comment.