public void Initialize_TestClassSwitchPropertiesEmptyLabel_ThrowsException() { TestClassSwitchPropertiesEmptyLabel instance = new TestClassSwitchPropertiesEmptyLabel(); ArgumentProcessor <TestClassSwitchPropertiesEmptyLabel> processor = new ArgumentProcessor <TestClassSwitchPropertiesEmptyLabel>(instance); Assert.Throws <SwitchAttributeException>(() => { processor.Initialize(); }); }
public void Initialize_TestClassOptionPropertiesSameBriefLabels_ThrowsException() { TestClassOptionPropertiesSameBriefLabels instance = new TestClassOptionPropertiesSameBriefLabels(); ArgumentProcessor <TestClassOptionPropertiesSameBriefLabels> processor = new ArgumentProcessor <TestClassOptionPropertiesSameBriefLabels>(instance); Assert.Throws <UtilizeViolationException>(() => { processor.Initialize(); }); }
public void ArgProc_SqaleFile() { // 0. Setup TestLogger logger; string[] rawArgs; ProcessedArgs actualArgs; // 1. No sqale file value -> valid logger = new TestLogger(); rawArgs = new string[] { "/a:validId" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsProcessed(actualArgs, logger, "validId", null, null); // 2. Missing sqale file logger = new TestLogger(); rawArgs = new string[] { "/s:missingFile.txt", "/a:validId" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsNotProcessed(actualArgs, logger); logger.AssertSingleErrorExists("missingFile.txt"); // should be an error containing the missing file name // 3. Existing sqale file string testDir = TestUtils.CreateTestDirectory(this.TestContext); string filePath = TestUtils.CreateTextFile("valid.sqale.txt", testDir, "sqale file contents"); logger = new TestLogger(); rawArgs = new string[] { "/s:" + filePath, "/a:valid:1.0" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsProcessed(actualArgs, logger, "valid", "1.0", filePath); }
public void Initialize_TestClassVerbalPropertiesWrongType_ThrowsException() { TestClassVerbalPropertiesWrongType instance = new TestClassVerbalPropertiesWrongType(); ArgumentProcessor <TestClassVerbalPropertiesWrongType> processor = new ArgumentProcessor <TestClassVerbalPropertiesWrongType>(instance); Assert.Throws <SupportViolationException>(() => { processor.Initialize(); }); }
public void Initialize_TestClassVerbalPropertiesUsedLabel_ThrowsException() { TestClassVerbalPropertiesUsedLabel instance = new TestClassVerbalPropertiesUsedLabel(); ArgumentProcessor <TestClassVerbalPropertiesUsedLabel> processor = new ArgumentProcessor <TestClassVerbalPropertiesUsedLabel>(instance); Assert.Throws <VerbalAttributeException>(() => { processor.Initialize(); }); }
public void Initialize_TestClassVerbalPropertiesManyTypes_ThrowsException() { TestClassVerbalPropertiesManyTypes instance = new TestClassVerbalPropertiesManyTypes(); ArgumentProcessor <TestClassVerbalPropertiesManyTypes> processor = new ArgumentProcessor <TestClassVerbalPropertiesManyTypes>(instance); Assert.Throws <VerbalViolationException>(() => { processor.Initialize(); }); }
public void ArgProc_AnalyzerRef_Valid() { // 0. Setup TestLogger logger; string[] rawArgs; ProcessedArgs actualArgs; // 1. Id but no version logger = new TestLogger(); rawArgs = new string[] { "/a:testing.id.no.version" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsProcessed(actualArgs, logger, "testing.id.no.version", null, false); // 2. Id and version logger = new TestLogger(); rawArgs = new string[] { "/analyzer:testing.id.with.version:1.0.0-rc1" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsProcessed(actualArgs, logger, "testing.id.with.version", "1.0.0-rc1", false); // 3. Id containing a colon, with version logger = new TestLogger(); rawArgs = new string[] { "/analyzer:id.with:colon:2.1.0" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsProcessed(actualArgs, logger, "id.with:colon", "2.1.0", false); }
public void ArgProc_AcceptLicensesInvalid() { // 0. Setup TestLogger logger; string[] rawArgs; ProcessedArgs actualArgs; // 1. Correct text, wrong case -> invalid logger = new TestLogger(); rawArgs = new string[] { "/a:validId", "/ACCEPTLICENSES" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsNotProcessed(actualArgs, logger); // 2. Unrecognized argument -> invalid logger = new TestLogger(); rawArgs = new string[] { "/a:validId", "/acceptLicenses=true" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsNotProcessed(actualArgs, logger); // 3. Unrecognized argument -> invalid logger = new TestLogger(); rawArgs = new string[] { "/a:validId", "/acceptLicensesXXX" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsNotProcessed(actualArgs, logger); }
private static int Main(string[] args) { ConsoleLogger logger = new ConsoleLogger(); Utilities.LogAssemblyVersion(typeof(Program).Assembly, UIResources.Program_AssemblyDescription, logger); Utilities.LogAssemblyVersion(typeof(DiagnosticAnalyzer).Assembly, UIResources.Program_SupportedRoslynVersion, logger); logger.LogInfo(UIResources.Program_SupportedSonarQubeVersions); ProcessedArgs processedArgs = ArgumentProcessor.TryProcessArguments(args, logger); bool success = false; if (processedArgs != null) { string localNuGetCache = Utilities.CreateTempDirectory(".nuget"); var defaultNuGetDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var repo = NuGetRepositoryFactory.CreateRepositoryForArguments(logger, processedArgs, defaultNuGetDir); var packageHandler = new NuGetPackageHandler(repo, localNuGetCache, logger); AnalyzerPluginGenerator generator = new AnalyzerPluginGenerator(packageHandler, logger); success = generator.Generate(processedArgs); } return(success ? SUCCESS_CODE : ERROR_CODE); }
public void PreArgProc_MissingArguments() { // 0. Setup TestLogger logger; // 1. Null logger Action act = () => ArgumentProcessor.TryProcessArgs(null, null); act.Should().ThrowExactly <ArgumentNullException>(); // 2. required argument missing logger = CheckProcessingFails(/* no command line args */); logger.AssertSingleErrorExists("/key:"); // we expect error with info about the missing required parameter, which should include the primary alias logger.AssertErrorsLogged(1); // 3. Only key and host URL are required var args = CheckProcessingSucceeds("/k:key", "/d:sonar.host.url=myurl"); "key".Should().Be(args.ProjectKey); "myurl".Should().Be(args.SonarQubeUrl); // 4. Argument is present but has no value logger = CheckProcessingFails("/key:"); logger.AssertSingleErrorExists("/key:"); logger.AssertErrorsLogged(1); }
public void PreArgProc_MissingArguments() { // 0. Setup TestLogger logger; // 1. Null logger AssertException.Expects <ArgumentNullException>(() => ArgumentProcessor.TryProcessArgs(null, null)); // 2. All required arguments missing logger = CheckProcessingFails(/* no command line args */); logger.AssertSingleErrorExists("/key:"); // we expect errors with info about the missing required parameters, which should include the primary alias logger.AssertSingleErrorExists("/name:"); logger.AssertSingleErrorExists("/version:"); logger.AssertErrorsLogged(3); // 3. Some required arguments missing logger = CheckProcessingFails("/k:key", "/v:version"); logger.AssertErrorDoesNotExist("/key:"); logger.AssertErrorDoesNotExist("/version:"); logger.AssertSingleErrorExists("/name:"); logger.AssertErrorsLogged(1); // 4. Argument is present but has no value logger = CheckProcessingFails("/key:k1", "/name:n1", "/version:"); logger.AssertErrorDoesNotExist("/key:"); logger.AssertErrorDoesNotExist("/name:"); logger.AssertSingleErrorExists("/version:"); logger.AssertErrorsLogged(1); }
public void ArgProc_RuleFile() { // 0. Setup TestLogger logger; string[] rawArgs; ProcessedArgs actualArgs; // 1. No rule file value -> valid logger = new TestLogger(); rawArgs = new string[] { "/a:validId" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); actualArgs.RuleFilePath.Should().BeNull(); // 2. Missing rule file logger = new TestLogger(); rawArgs = new string[] { "/rules:missingFile.txt", "/a:validId" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsNotProcessed(actualArgs, logger); logger.AssertSingleErrorExists("missingFile.txt"); // should be an error containing the missing file name // 3. Existing rule file string testDir = TestUtils.CreateTestDirectory(this.TestContext); string filePath = TestUtils.CreateTextFile("valid.rules.txt", testDir, "rule file contents"); logger = new TestLogger(); rawArgs = new string[] { $"/rules:{filePath}", "/a:valid:1.0" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); actualArgs.Should().NotBeNull(); actualArgs.RuleFilePath.Should().Be(filePath); }
public void Initialize_TestClassVerbalProperties_ResultIsZeroSettingsCount() { TestClassVerbalProperties instance = new TestClassVerbalProperties(); ArgumentProcessor <TestClassVerbalProperties> processor = new ArgumentProcessor <TestClassVerbalProperties>(instance); processor.Initialize(); Assert.AreEqual(processor.Settings.Count, 1); }
public void ArgProc_Help() { Assert.IsTrue(ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/h" })); Assert.IsFalse(ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/hr" })); Assert.IsTrue(ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/?" })); Assert.IsFalse(ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/??" })); }
public void TryProcessArgs_WhenCommandLineArgsIsNull_ThrowsArgumentNullException() { // Arrange Action action = () => ArgumentProcessor.TryProcessArgs(null, new TestLogger(), out var settings); // Act & Assert action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("commandLineArgs"); }
public void ArgProc_Help() { ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/h" }).Should().BeTrue(); ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/hr" }).Should().BeFalse(); ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/?" }).Should().BeTrue(); ArgumentProcessor.IsHelp(new string[] { "sad", "/d:s=r", "/??" }).Should().BeFalse(); }
public void TryProcessArgs_WhenLoggerIsNull_ThrowsArgumentNullException() { // Arrange Action action = () => ArgumentProcessor.TryProcessArgs(new string[0], null, out var settings); // Act & Assert action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("logger"); }
public void ArgumentProcessorShouldEscapeQuotes() { Assert.Equal( "\"a \\\" b\" c", ArgumentProcessor.CygwinArgumentsToString(new[] { "a \" b", "c" })); }
public void ArgProc_CustomNuGetRepository_Path() { var logger = new TestLogger(); var rawArgs = new string[] { "/a:validId", "/customnugetrepo:file:///somelocalrepo/path" }; var actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); actualArgs.CustomNuGetRepository.Should().Be("file:///somelocalrepo/path"); }
public void ArgProc_CustomNuGetRepository_Default() { var logger = new TestLogger(); var rawArgs = new string[] { "/a:validId" }; var actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); actualArgs.CustomNuGetRepository.Should().BeNull(); }
public void ArgProc_OutputDirectory_Default() { var logger = new TestLogger(); var rawArgs = new string[] { "/a:validId" }; var actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); actualArgs.OutputDirectory.Should().Be(Directory.GetCurrentDirectory()); }
public void ArgProc_OutputDirectory_Parameter() { var logger = new TestLogger(); var rawArgs = new string[] { "/a:validId", "/o:My/Output/Directory" }; var actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); actualArgs.OutputDirectory.Should().Be("My/Output/Directory"); }
public void ArgumentProcessorShouldPutQuotesAroundSpaces() { Assert.Equal( "\"a b\" c", ArgumentProcessor.CygwinArgumentsToString(new[] { "a b", "c" })); }
public void ArgumentProcessorShouldPutSpaceBetweenArguments() { Assert.Equal( "a b c", ArgumentProcessor.CygwinArgumentsToString(new[] { "a", "b", "c" })); }
private static IAnalysisPropertyProvider CheckProcessingSucceeds(TestLogger logger, string[] input) { var success = ArgumentProcessor.TryProcessArgs(input, logger, out IAnalysisPropertyProvider provider); success.Should().BeTrue("Expecting processing to have succeeded"); provider.Should().NotBeNull("Returned provider should not be null"); logger.AssertErrorsLogged(0); return(provider); }
private static IAnalysisPropertyProvider CheckProcessingSucceeds(TestLogger logger, string[] input) { bool success = ArgumentProcessor.TryProcessArgs(input, logger, out IAnalysisPropertyProvider provider); Assert.IsTrue(success, "Expecting processing to have succeeded"); Assert.IsNotNull(provider, "Returned provider should not be null"); logger.AssertErrorsLogged(0); return(provider); }
private static IBootstrapperSettings CheckProcessingSucceeds(TestLogger logger, params string[] cmdLineArgs) { var success = ArgumentProcessor.TryProcessArgs(cmdLineArgs, logger, out IBootstrapperSettings settings); Assert.IsTrue(success, "Expecting processing to succeed"); Assert.IsNotNull(settings, "Settings should not be null if processing succeeds"); logger.AssertErrorsLogged(0); return(settings); }
private static TestLogger CheckProcessingFails(params string[] commandLineArgs) { TestLogger logger = new TestLogger(); ProcessedArgs result = ArgumentProcessor.TryProcessArgs(commandLineArgs, logger); Assert.IsNull(result, "Not expecting the arguments to be processed succesfully"); logger.AssertErrorsLogged(); return(logger); }
private static TestLogger CheckProcessingFails(params string[] cmdLineArgs) { var logger = new TestLogger(); var success = ArgumentProcessor.TryProcessArgs(cmdLineArgs, logger, out IBootstrapperSettings settings); Assert.IsFalse(success, "Expecting processing to fail"); Assert.IsNull(settings, "Settings should be null if processing fails"); logger.AssertErrorsLogged(); return(logger); }
private static ProcessedArgs CheckProcessingSucceeds(params string[] commandLineArgs) { var logger = new TestLogger(); var result = ArgumentProcessor.TryProcessArgs(commandLineArgs, logger); Assert.IsNotNull(result, "Expecting the arguments to be processed successfully"); logger.AssertErrorsLogged(0); return(result); }
static void Main(string[] Args) { // Command line parsing ArgumentProcessor CommandLine = new ArgumentProcessor(Args); string inputFilename; string outputFilename; // Look for specific arguments values and display them if they exist (return null if they don't) inputFilename = CommandLine["i"]; if (CommandLine["i"] != null) Console.WriteLine("i value: " + CommandLine["i"]); else Console.WriteLine("i not defined !"); outputFilename = CommandLine["o"]; if (CommandLine["o"] != null) Console.WriteLine("o value: " + CommandLine["o"]); else Console.WriteLine("o not defined !"); PluginManager.PluginManager manager = new PluginManager.PluginManager(); foreach (string name in manager.PluginNames) { Console.Out.WriteLine("Loaded Plugin " + name); } MuxEngine.MuxEngine engine = new MuxEngine.MuxEngine(manager); engine.AddInput(inputFilename); engine.OutputFilename = outputFilename; engine.Start(); while (engine.Complete == false) { Thread.Sleep(100); } Console.Out.WriteLine("Muxing is complete."); Console.Out.WriteLine("Frames Muxed: " + engine.FramesMuxed); Console.Out.WriteLine("Time Elapsed: " + engine.TimeElapsed); // Wait for key Console.Out.WriteLine("Press any key..."); Console.Read(); }
private void Setup() { _target = new ArgumentProcessorTarget(); Isolate.WhenCalled(() => _target.SomeMethod()).IgnoreCall(); _processor = new ArgumentProcessor<ArgumentProcessorTarget>(_target); _args = new List<string>(); }
public void ArgumentProcessor_CorrectlySetsSeralizationFolder() { var processor = new ArgumentProcessor(new[] { "Data", "", "", "" }); Assert.AreEqual("Data", processor.SerializationFolder); }
public void ArgumentProcessor_CorrectlySetsCurrentGitCommitId() { var processor = new ArgumentProcessor(new[] { "", "", "12345", "" }); Assert.AreEqual("12345", processor.CurrentCommitId); }
public void ArgumentProcessor_CorrectlySetsDestinationFolder() { var processor = new ArgumentProcessor(new[] { "", "Destination", "", "" }); Assert.AreEqual("Destination", processor.PackageDestinationFolder); }