Example #1
0
        public void FileLoc_GetSonarRunnerProperties()
        {
            // 0. Set up
            string runnerRootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            string binDir        = TestUtils.EnsureTestSpecificFolder(this.TestContext, "bin");
            string configDir     = TestUtils.EnsureTestSpecificFolder(this.TestContext, "conf");

            string runnerFile = Path.Combine(binDir, FileLocator.SonarRunnerFileName);

            File.WriteAllText(runnerFile, "dummy runner file");

            string configFile = Path.Combine(configDir, "sonar-runner.properties");

            File.WriteAllText(configFile, "dummy runner properties file");

            using (TestUtilities.EnvironmentVariableScope scope = new TestUtilities.EnvironmentVariableScope())
            {
                // 1. Runner not found on path -> nothing
                scope.SetPath("c:\\");
                string actual = FileLocator.FindDefaultSonarRunnerProperties();
                Assert.IsNull(actual, "Not expecting the runner properties file to be found");


                // 2. Runner found on path but no properties file -> not found
                scope.SetPath("c:\\;" + binDir);
                File.Delete(configFile);

                using (new AssertIgnoreScope())
                {
                    actual = FileLocator.FindDefaultSonarRunnerProperties();
                }
                Assert.IsNull(actual, "Not expecting the runner properties file to be found");


                // 3. Runner found on path and config file exists in expected relative location -> found

                // Create the properties file in the expected location
                configFile = Path.Combine(configDir, "sonar-runner.properties");
                File.WriteAllText(configFile, "dummy runner properties file");

                actual = FileLocator.FindDefaultSonarRunnerProperties();
                Assert.IsNotNull(actual, "Expecting the runner properties file to be found");
                Assert.AreEqual(configFile, actual, "Unexpected file name returned");
            }
        }
Example #2
0
        public void FileLoc_GetSonarRunner()
        {
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string runnerFile = Path.Combine(testDir, FileLocator.SonarRunnerFileName);

            File.WriteAllText(runnerFile, "dummy runner file");

            using (TestUtilities.EnvironmentVariableScope scope = new TestUtilities.EnvironmentVariableScope())
            {
                // 1. Not found on path
                scope.SetPath("c:\\");
                string actual = FileLocator.FindDefaultSonarRunnerExecutable();
                Assert.IsNull(actual, "Not expecting the file to be found");

                // 2. Found on path
                scope.SetPath("c:\\;" + testDir);
                actual = FileLocator.FindDefaultSonarRunnerExecutable();
                Assert.IsNotNull(actual, "Expecting the runner file to be found");
                Assert.AreEqual(runnerFile, actual, "Unexpected file name returned");
            }
        }