Example #1
0
        public void BuildPackageAndCheckServiceability(string projectName, bool expectedServiceability)
        {
            var rootDir = ProjectResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var projectSrcDir = Path.Combine(rootDir, "misc", "ServicingTestProjects", projectName);
            const string configuration = "Debug";

            var components = TestUtils.GetRuntimeComponentsCombinations().First();
            var flavor = (string)components[0];
            var os = (string)components[1];
            var architecture = (string)components[2];

            using (var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture))
            using (var tempDir = new DisposableDir())
            {
                var projectDir = Path.Combine(tempDir, projectName);
                var buildOutpuDir = Path.Combine(tempDir, "output");
                TestUtils.CopyFolder(projectSrcDir, projectDir);

                var exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", projectDir);
                Assert.Equal(0, exitCode);

                exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    "pack",
                    $"{projectDir} --out {buildOutpuDir} --configuration {configuration}");

                Assert.Equal(0, exitCode);

                var assemblyPath = Path.Combine(buildOutpuDir, configuration, "dnx451", $"{projectName}.dll");
                Assert.Equal(expectedServiceability, LockFileUtils.IsAssemblyServiceable(assemblyPath));
            }
        }
Example #2
0
        public void DnuPack_DoesNotExecutePostBuildScriptWhenBuildFails(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            var projectJson = @"{
              ""scripts"": {
            ""postbuild"": ""echo POST_BUILD_SCRIPT_OUTPUT"",
            ""postpack"": ""echo POST_PACK_SCRIPT_OUTPUT""
              },
            }";
            var sourceFileContents = @"Invalid source code that makes build fail";

            using (var tempDir = new DisposableDir())
            {
                var projectJsonPath = Path.Combine(tempDir, Runtime.Project.ProjectFileName);
                var sourceFilePath = Path.Combine(tempDir, "Program.cs");
                File.WriteAllText(projectJsonPath, projectJson);
                File.WriteAllText(sourceFilePath, sourceFileContents);

                string stdOut, stdErr;
                var exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    "pack",
                    projectJsonPath,
                    out stdOut,
                    out stdErr);

                Assert.NotEqual(0, exitCode);
                Assert.NotEmpty(stdErr);
                Assert.DoesNotContain("POST_BUILD_SCRIPT_OUTPUT", stdOut);
                Assert.DoesNotContain("POST_PACK_SCRIPT_OUTPUT", stdOut);
            }
        }
Example #3
0
        public void CanSpecifyProjectDirectoryInGlobalJson()
        {
            var solutionStructure = @"{
              'global.json': '',
              'src': {
            'ProjectA': {
              'project.json': '{}'
            }
              },
              'ProjectB': {
            'project.json': '{}'
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src"", ""ProjectB""]
            }")
                    .WriteTo(solutionPath);

                var resolutionRoot = Path.Combine(solutionPath, "src", "ProjectA");

                Project project;
                Assert.True(new ProjectResolver(resolutionRoot).TryResolveProject("ProjectB", out project));
                Assert.NotNull(project);
            }
        }
        private void CreateNewPackage(string name, string version)
        {
            var runtimeForPacking = TestUtils.GetClrRuntimeComponents().FirstOrDefault();
            if (runtimeForPacking == null)
            {
                throw new InvalidOperationException("Can't find a CLR runtime to pack test packages.");
            }

            var runtimeHomePath = base.GetRuntimeHomeDir((string)runtimeForPacking[0],
                                                         (string)runtimeForPacking[1],
                                                         (string)runtimeForPacking[2]);

            using (var tempdir = new DisposableDir())
            {
                var dir = new DirectoryInfo(tempdir);
                var projectDir = dir.CreateSubdirectory(name);
                var outputDir = dir.CreateSubdirectory("output");
                var projectJson = Path.Combine(projectDir.FullName, "project.json");

                File.WriteAllText(projectJson, $@"{{
  ""version"": ""{version}"",
  ""frameworks"": {{ 
      ""dnx451"": {{ }}
  }}
}}");
                DnuTestUtils.ExecDnu(runtimeHomePath, "restore", projectJson);
                DnuTestUtils.ExecDnu(runtimeHomePath, "pack", projectJson + " --out " + outputDir.FullName, environment: null, workingDir: null);

                var packageName = string.Format("{0}.{1}.nupkg", name, version);
                var packageFile = Path.Combine(outputDir.FullName, "Debug", packageName);

                File.Copy(packageFile, Path.Combine(PackageSource, packageName), overwrite: true);
            }
        }
Example #5
0
 public DnuTestEnvironment(string runtimePath, string projectName = null, string outputDirName = null)
 {
     _projectName = projectName ?? "ProjectName";
     _outputDirName = outputDirName ?? "OutputDirName";
     _runtimePath = runtimePath;
     RootDir = new DisposableDir();
 }
Example #6
0
        public void ReadResourcesFromProjectNugetPackageAndClassLibrary(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var tempDir = new DisposableDir())
            {
                var appPath = Path.Combine(tempDir, "ResourcesTestProjects", "ReadFromResources");
                TestUtils.CreateDisposableTestProject(runtimeHomeDir, Path.Combine(tempDir, "ResourcesTestProjects"), Path.Combine(TestUtils.GetMiscProjectsFolder(), "ResourcesTestProjects", "ReadFromResources"));

                string stdOut;
                string stdErr;
                var exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "-p . run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary<string, string> { { EnvironmentNames.Trace, null } },
                    workingDir: Path.Combine(appPath, "src", "ReadFromResources"));

                Assert.Equal(0, exitCode);
                Assert.Contains(@"Hello World!
Bonjour Monde!
Hallo Welt
Bienvenue
The name '{0}' is ambiguous.
Le nom '{0}' est ambigu.
In TestClass
", stdOut);
            }
        }
Example #7
0
        public void ReadEmbeddedResourcesFromProject(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var tempDir = new DisposableDir())
            {
                var appPath = Path.Combine(tempDir, "ResourcesTestProjects", "EmbeddedResources");
                TestUtils.CreateDisposableTestProject(runtimeHomeDir, Path.Combine(tempDir, "ResourcesTestProjects"), Path.Combine(TestUtils.GetMiscProjectsFolder(), "ResourcesTestProjects", "EmbeddedResources"));

                string stdOut;
                string stdErr;
                var exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "-p . run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary<string, string> { { EnvironmentNames.Trace, null } },
                    workingDir: appPath);

                Assert.Equal(0, exitCode);
                Assert.Contains(@"Hello
<html>
Basic Test
</html>
", stdOut);
            }
        }
Example #8
0
        public void DnuRestore_DoesFallback(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            LockFile lockFile;
            using (var testDir = new DisposableDir())
            {
                var misc = TestUtils.GetMiscProjectsFolder();
                DirTree.CreateFromDirectory(Path.Combine(misc, "RuntimeRestore", "TestProject"))
                    .WriteTo(testDir);

                // Clean up the lock file if it ended up there during the copy
                var lockFilePath = Path.Combine(testDir, "project.lock.json");
                if (File.Exists(lockFilePath))
                {
                    File.Delete(lockFilePath);
                }

                // Restore the project!
                var source = Path.Combine(misc, "RuntimeRestore", "RuntimeRestoreTestPackage", "feed");
                DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", $"--source {source} --runtime win10-x64 --runtime win10-x86 --runtime ubuntu.14.04-x86", workingDir: testDir);

                // Check the lock file
                lockFile = (new LockFileFormat()).Read(Path.Combine(testDir, "project.lock.json"));
            }

            AssertLockFileTarget(lockFile, "win10-x64", "win7-x64");
            AssertLockFileTarget(lockFile, "win10-x86", "win8-x86");
            AssertLockFileTarget(lockFile, "ubuntu.14.04-x86", assemblyRid: null);
        }
Example #9
0
        public void ProjectResolverChecksProjectFileForDisambiguation()
        {
            const string projectName = "ProjectA";
            var solutionStructure = @"{
              'global.json': '',
              'src1': {
            'ProjectA': {
              'project.json': '{}'
            }
              },
              'src2': {
            'ProjectA': {
              'file.txt': 'Not a project.json'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src1"", ""src2""]
            }")
                    .WriteTo(solutionPath);

                var projectPath = Path.Combine(solutionPath, "src1", projectName);

                Project project;
                Assert.True(new ProjectResolver(projectPath).TryResolveProject(projectName, out project));
                Assert.NotNull(project);
            }
        }
Example #10
0
        public void DnuRestore_GeneratesDefaultRuntimeTargets(string flavor, string os, string architecture)
        {
            // TODO(anurse): Maybe this could be a condition? This is the only place we need it right now so it
            // didn't seem worth the refactor.
            // Travis has old versions of OSes and our test package doesn't work there
            var isTravisEnvironment = Environment.GetEnvironmentVariable("TRAVIS") ?? "false";
            if (isTravisEnvironment.Equals("true"))
            {
                return;
            }

            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            LockFile lockFile;
            using (var testDir = new DisposableDir())
            {
                var misc = TestUtils.GetMiscProjectsFolder();
                DirTree.CreateFromDirectory(Path.Combine(misc, "RuntimeRestore", "TestProject"))
                    .WriteTo(testDir);

                // Clean up the lock file if it ended up there during the copy
                var lockFilePath = Path.Combine(testDir, "project.lock.json");
                if (File.Exists(lockFilePath))
                {
                    File.Delete(lockFilePath);
                }

                // Restore the project!
                var source = Path.Combine(misc, "RuntimeRestore", "RuntimeRestoreTestPackage", "feed");
                DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", $"--source {source}", workingDir: testDir);

                // Check the lock file
                lockFile = (new LockFileFormat()).Read(Path.Combine(testDir, "project.lock.json"));
            }

            // We can use the runtime environment to determine the expected RIDs
            var osName = RuntimeEnvironmentHelper.RuntimeEnvironment.GetDefaultRestoreRuntimes().First();
            if (osName.StartsWith("win"))
            {
                AssertLockFileTarget(lockFile, "win7-x86", "win7-x86");
                AssertLockFileTarget(lockFile, "win7-x64", "win7-x64");
            }
            else if (osName.StartsWith("ubuntu"))
            {
                // There is only ubuntu 14.04 in the package
                AssertLockFileTarget(lockFile, osName + "-x86", assemblyRid: null); // There is no ubuntu/osx-x86 in the test package
                AssertLockFileTarget(lockFile, osName + "-x64", "ubuntu.14.04-x64");
            }
            else if (osName.StartsWith("osx"))
            {
                // There is only osx 10.10 in the package
                AssertLockFileTarget(lockFile, osName + "-x86", assemblyRid: null); // There is no ubuntu/osx-x86 in the test package
                AssertLockFileTarget(lockFile, osName + "-x64", "osx.10.10-x64");
            }
            else
            {
                Assert.True(false, $"Unknown OS Name: {osName}");
            }
        }
Example #11
0
 public void Dispose()
 {
     if (Root != null)
     {
         Root.Dispose();
         Root = null;
     }
 }
Example #12
0
        public static DisposableDir GetTempTestSolution(string name)
        {
            var rootDir            = ProjectRootResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var sourceSolutionPath = Path.Combine(rootDir, "misc", "DnuWrapTestSolutions", name);
            var targetSolutionPath = new DisposableDir();

            CopyFolder(sourceSolutionPath, targetSolutionPath);
            return(targetSolutionPath);
        }
        public PackageManagerFunctionalTestFixture() : base()
        {
            _contextDir = new DisposableDir();
            PackageSource = Path.Combine(_contextDir.DirPath, "packages");
            Directory.CreateDirectory(PackageSource);

            CreateNewPackage("alpha", "0.1.0");

            PackPackage(Path.Combine(TestUtils.GetMiscProjectsFolder(), "XreTestApps/CommandsProject"), PackageSource);
        }
Example #14
0
        public static DisposableDir GetRuntimeHomeDir(string flavor, string os, string architecture)
        {
            var useDevBuild      = Environment.GetEnvironmentVariable("DNX_DEV");
            var buildArtifactDir = GetBuildArtifactsFolder();
            var runtimeName      = GetRuntimeName(flavor, os, architecture);

            // For rapid development, allow using in place dev builds
            if (string.Equals(useDevBuild, "1"))
            {
                var artifacts = GetBuildArtifactsFolder();

                return(new DisposableDir(Path.Combine(artifacts, runtimeName), deleteOnDispose: false));
            }

            // The build script creates an unzipped image that can be reused
            var testArtifactDir = GetTestArtifactsFolder();
            var runtimeHomePath = Path.Combine(testArtifactDir, runtimeName);
            var runtimePath     = Path.Combine(runtimeHomePath, "runtimes");

            if (Directory.Exists(runtimePath))
            {
                // Don't dispose this because it's shared across all functional tests
                return(new DisposableDir(runtimeHomePath, deleteOnDispose: false));
            }

            // We're running an individual tests
            var runtimeNupkg = Directory.GetFiles(
                buildArtifactDir,
                GetRuntimeFilePattern(flavor, os, architecture),
                SearchOption.TopDirectoryOnly).First();

            runtimeHomePath = new DisposableDir();
            runtimeName     = Path.GetFileNameWithoutExtension(runtimeNupkg);
            var runtimeRoot = Path.Combine(runtimeHomePath, "runtimes", runtimeName);

            if (!RuntimeEnvironmentHelper.IsMono)
            {
                System.IO.Compression.ZipFile.ExtractToDirectory(runtimeNupkg, runtimeRoot);
            }
            else
            {
                Directory.CreateDirectory(runtimeRoot);
                Exec("unzip", runtimeNupkg + " -d " + runtimeRoot);
                // We need to mark these files because unzip doesn't preserve the exec bit
                Exec("chmod", "+x " + Path.Combine(runtimeRoot, "bin", "dnx"));
                Exec("chmod", "+x " + Path.Combine(runtimeRoot, "bin", "dnu"));
            }

            return(runtimeHomePath);
        }
Example #15
0
        public void ProjectResolverThrowsWhenResolvingAmbiguousName()
        {
            const string ambiguousName = "ProjectA";
            var solutionStructure = @"{
  'global.json': '',
  'src1': {
    'ProjectA': {
      'project.json': '{}'
    }
  },
  'src2': {
    'ProjectA': {
      'project.json': '{}'
    }
  }
}";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
  ""projects"": [""src1"", ""src2""]
}")
                    .WriteTo(solutionPath);

                var src1ProjectPath = Path.Combine(solutionPath, "src1", ambiguousName);
                var src2ProjectPath = Path.Combine(solutionPath, "src2", ambiguousName);
                var expectedMessage = $@"The project name '{ambiguousName}' is ambiguous between the following projects:
{src1ProjectPath}
{src2ProjectPath}";

                Runtime.Project project = null;
                var resolver1 = new ProjectResolver(src1ProjectPath);
                var exception = Assert.Throws<InvalidOperationException>(() => resolver1.TryResolveProject(ambiguousName, out project));
                Assert.Contains(expectedMessage, exception.Message);
                Assert.Null(project);

                var resolver2 = new ProjectResolver(src2ProjectPath);
                exception = Assert.Throws<InvalidOperationException>(() => resolver2.TryResolveProject(ambiguousName, out project));
                Assert.Contains(expectedMessage, exception.Message);
                Assert.Null(project);
            }
        }
Example #16
0
        public static DisposableDir PrepareTemporarySamplesFolder(string runtimeHomeDir)
        {
            var tempDir = new DisposableDir();

            TestUtils.CopyFolder(TestUtils.GetSamplesFolder(), tempDir);

            // Make sure sample projects depend on runtime components from newly built dnx
            var currentDnxSolutionRootDir = ProjectRootResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var currentDnxSolutionSrcPath = Path.Combine(currentDnxSolutionRootDir, "src").Replace("\\", "\\\\");
            var samplesGlobalJson         = new JObject();

            samplesGlobalJson["projects"] = new JArray(new[] { currentDnxSolutionSrcPath });
            File.WriteAllText(Path.Combine(tempDir, GlobalSettings.GlobalFileName), samplesGlobalJson.ToString());

            // Make sure package restore can be successful
            const string nugetConfigName = "NuGet.config";

            File.Copy(Path.Combine(currentDnxSolutionRootDir, nugetConfigName), Path.Combine(tempDir, nugetConfigName));

            // Use the newly built runtime to generate lock files for samples
            string stdOut, stdErr;
            int    exitCode;

            foreach (var projectDir in Directory.EnumerateDirectories(tempDir))
            {
                exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    subcommand: "restore",
                    arguments: projectDir,
                    stdOut: out stdOut,
                    stdErr: out stdErr);

                if (exitCode != 0)
                {
                    Console.WriteLine(stdOut);
                    Console.WriteLine(stdErr);
                }
            }

            return(tempDir);
        }
Example #17
0
        public void DnuInstall_WithoutProjectPathArgument(string flavor, string os, string architecture)
        {
            var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            using (var tempDir = new DisposableDir())
            {
                var packagesDir = Path.Combine(tempDir, "packages");
                var projectDir = Path.Combine(tempDir, "project");
                Directory.CreateDirectory(projectDir);
                var projectJsonPath = Path.Combine(projectDir, Runtime.Project.ProjectFileName);
                File.WriteAllText(projectJsonPath, @"{
  ""dependencies"": { }
}");

                VerifyDnuInstall(
                    runtimeHomePath,
                    packageName: "alpha",
                    packageVersion: "0.1.0",
                    projectDir: null,
                    packagesDir: packagesDir,
                    workingDir: projectDir);
            }
        }
Example #18
0
        public void ApplicationScriptsHaveTheCorrectContent()
        {
            using (DisposableDir tempDir = new DisposableDir())
            {
                string testDir = Path.Combine(tempDir, "TestApp");
                Directory.CreateDirectory(testDir);

                string projectFilePath = Path.Combine(testDir, "project.json");
                string projectFileContent =
                @"{ 
                    ""commands"" : { 
                        ""cmd1"":""demo1"",
                        ""cmd2"":""demo2""
                    } 
                }";
                File.WriteAllText(projectFilePath, projectFileContent);

                Runtime.Project project;
                Runtime.Project.TryGetProject(projectFilePath, out project);
                
                var packageManager = new MockPackageManager();
                var infoReport = new MockReport();

                var builder = new InstallBuilder(
                    project,
                    packageManager,
                    new Reports()
                    {
                        Information = infoReport,
                        Verbose = new MockReport()
                    });

                Assert.True(builder.Build(testDir));

                ValidateProjectFile(Path.Combine(testDir, "app", "project.json"));
                ValidateScriptFile(Path.Combine(testDir, "app", "cmd1.cmd"));
                ValidateScriptFile(Path.Combine(testDir, "app", "cmd2.cmd"));
            }
        }
Example #19
0
        public void AppHostShowsErrorWhenGivenSubcommandWasNotFoundInProjectJson(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            var projectStructure = @"{
              ""project.json"": ""{ }""
            }";

            using (var projectPath = new DisposableDir())
            {
                DirTree.CreateFromJson(projectStructure)
                       .WithFileContents("project.json", @"
            {
            ""frameworks"": {
            ""dnx451"": { },
            ""dnxcore50"": { }
            }
            }").WriteTo(projectPath);

                string stdOut, stdErr;
                var exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "invalid",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary<string, string> { },
                    workingDir: projectPath);

                Assert.NotEqual(0, exitCode);
                Assert.Contains("Unable to load application or execute command 'invalid'.", stdErr);
            }
        }
Example #20
0
        public static DisposableDir PrepareTemporarySamplesFolder(string runtimeHomeDir)
        {
            var tempDir = new DisposableDir();
            TestUtils.CopyFolder(TestUtils.GetSamplesFolder(), tempDir);

            // Make sure sample projects depend on runtime components from newly built dnx
            var currentDnxSolutionRootDir = ProjectRootResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var currentDnxSolutionSrcPath = Path.Combine(currentDnxSolutionRootDir, "src").Replace("\\", "\\\\");
            var samplesGlobalJson = new JObject();
            samplesGlobalJson["projects"] = new JArray(new[] { currentDnxSolutionSrcPath });
            File.WriteAllText(Path.Combine(tempDir, GlobalSettings.GlobalFileName), samplesGlobalJson.ToString());

            // Make sure package restore can be successful
            const string nugetConfigName = "NuGet.config";
            File.Copy(Path.Combine(currentDnxSolutionRootDir, nugetConfigName), Path.Combine(tempDir, nugetConfigName));

            // Use the newly built runtime to generate lock files for samples
            string stdOut, stdErr;
            int exitCode;
            foreach (var projectDir in Directory.EnumerateDirectories(tempDir))
            {
                exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    subcommand: "restore",
                    arguments: projectDir,
                    stdOut: out stdOut,
                    stdErr: out stdErr);

                if (exitCode != 0)
                {
                    Console.WriteLine(stdOut);
                    Console.WriteLine(stdErr);
                }
            }

            return tempDir;
        }
Example #21
0
 public static DisposableDir GetTempTestSolution(string name)
 {
     var rootDir = ProjectRootResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
     var sourceSolutionPath = Path.Combine(rootDir, "misc", "DnuWrapTestSolutions", name);
     var targetSolutionPath = new DisposableDir();
     CopyFolder(sourceSolutionPath, targetSolutionPath);
     return targetSolutionPath;
 }
Example #22
0
        public static DisposableDir GetRuntimeHomeDir(string flavor, string os, string architecture)
        {
            var useDevBuild = Environment.GetEnvironmentVariable("DNX_DEV");
            var buildArtifactDir = GetBuildArtifactsFolder();
            var runtimeName = GetRuntimeName(flavor, os, architecture);

            // For rapid development, allow using in place dev builds
            if (string.Equals(useDevBuild, "1"))
            {
                var artifacts = GetBuildArtifactsFolder();

                return new DisposableDir(Path.Combine(artifacts, runtimeName), deleteOnDispose: false);
            }

            // The build script creates an unzipped image that can be reused
            var testArtifactDir = GetTestArtifactsFolder();
            var runtimeHomePath = Path.Combine(testArtifactDir, runtimeName);
            var runtimePath = Path.Combine(runtimeHomePath, "runtimes");

            if (Directory.Exists(runtimePath))
            {
                // Don't dispose this because it's shared across all functional tests
                return new DisposableDir(runtimeHomePath, deleteOnDispose: false);
            }

            // We're running an individual tests
            var runtimeNupkg = Directory.GetFiles(
                buildArtifactDir,
                GetRuntimeFilePattern(flavor, os, architecture),
                SearchOption.TopDirectoryOnly).First();
            runtimeHomePath = new DisposableDir();
            runtimeName = Path.GetFileNameWithoutExtension(runtimeNupkg);
            var runtimeRoot = Path.Combine(runtimeHomePath, "runtimes", runtimeName);

            if (!RuntimeEnvironmentHelper.IsMono)
            {
                System.IO.Compression.ZipFile.ExtractToDirectory(runtimeNupkg, runtimeRoot);
            }
            else
            {
                Directory.CreateDirectory(runtimeRoot);
                Exec("unzip", runtimeNupkg + " -d " + runtimeRoot);
                // We need to mark these files because unzip doesn't preserve the exec bit
                Exec("chmod", "+x " + Path.Combine(runtimeRoot, "bin", "dnx"));
                Exec("chmod", "+x " + Path.Combine(runtimeRoot, "bin", "dnu"));
            }

            return runtimeHomePath;
        }
Example #23
0
        public void BootstrapperConfiguresAppConfigFile(string flavor, string os, string architecture)
        {
            const string projectStructure = @"{
    ""project.json"": {},
    ""project.lock.json"": {},
    ""app.config"": {},
    ""Program.cs"": {}
}";

            const string projectJson = @" {
    ""frameworks"": {
        ""dnx451"": {
            ""frameworkAssemblies"": {
                ""System.Configuration"": """"
            }
        }
    }
}";
            const string appConfig = @"<configuration>
  <appSettings>
    <add key=""TheSetting"" value=""TheValue"" />
  </appSettings>
</configuration>";

            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            using (var tempDir = new DisposableDir())
            {
                DirTree.CreateFromJson(projectStructure)
                    .WithFileContents("project.json", projectJson)
                    .WithFileContents("app.config", appConfig)
                    .WithFileContents("Program.cs", AppSettingTestProgram)
                    .WriteTo(tempDir);

                string stdOut;
                string stdErr;
                var exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: $"run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary<string, string> { { EnvironmentNames.Trace, null } },
                    workingDir: tempDir);
                Assert.Equal(0, exitCode);
                Assert.Contains("TheSetting=TheValue", stdOut.Trim());
            }
        }
Example #24
0
        public void BootstrapperLaunchesRequestedFramworkVersionIfOptionProvided(string flavor, string os, string architecture, string requestedFramework, string expectedOutput)
        {
            const string projectStructure = @"{
    ""project.json"": {},
    ""project.lock.json"": {},
    ""Program.cs"": {}
}";

            const string projectJson = @"{
    ""dependencies"": {
    },
    ""frameworks"": {
        ""dnx46"": {},
        ""dnx452"": {},
        ""dnx451"": {}
    }
}";
            const string lockFile = @"{
  ""locked"": false,
  ""version"": 2,
  ""targets"": {
    ""DNX,Version=v4.5.1"": {},
    ""DNX,Version=v4.5.2"": {},
    ""DNX,Version=v4.6"": {}
  },
  ""libraries"": {},
  ""projectFileDependencyGroups"": {
    """": [],
    ""DNX,Version=v4.5.1"": [],
    ""DNX,Version=v4.5.2"": [],
    ""DNX,Version=v4.6"": []
  }
}";

            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            using (var tempDir = new DisposableDir())
            {
                DirTree.CreateFromJson(projectStructure)
                    .WithFileContents("project.json", projectJson)
                    .WithFileContents("project.lock.json", lockFile)
                    .WithFileContents("Program.cs", ClrVersionTestProgram)
                    .WriteTo(tempDir);

                string stdOut;
                string stdErr;
                var exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: $"--framework {requestedFramework} run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary<string, string> { { EnvironmentNames.Trace, null } },
                    workingDir: tempDir);
                Assert.Equal(0, exitCode);
                Assert.Contains(expectedOutput, stdOut.Trim());
            }
        }
Example #25
0
        public void BootstrapperInvokesAssemblyWithInferredAppBaseAndLibPathOnClr(string flavor, string os, string architecture)
        {
            var outputFolder = flavor == "coreclr" ? "dnxcore50" : "dnx451";
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var tempSamplesDir = TestUtils.PrepareTemporarySamplesFolder(runtimeHomeDir))
            using (var tempDir = new DisposableDir())
            {
                var sampleAppRoot = Path.Combine(tempSamplesDir, "HelloWorld");

                string stdOut, stdErr;
                var exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    subcommand: "build",
                    arguments: string.Format("{0} --configuration=Release --out {1}", sampleAppRoot, tempDir),
                    stdOut: out stdOut,
                    stdErr: out stdErr);

                if (exitCode != 0)
                {
                    Console.WriteLine(stdOut);
                    Console.WriteLine(stdErr);
                }

                exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: Path.Combine(tempDir, "Release", outputFolder, "HelloWorld.dll"),
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary<string, string> { { EnvironmentNames.Trace, null } });

                Assert.Equal(0, exitCode);
                Assert.Contains(@"Hello World!
Hello, code!
", stdOut);
            }
        }
Example #26
0
        public void DnuPack_ResourcesNoArgs_WarningAsErrorsCompilationOption(string flavor, string os, string architecture)
        {
            string stdOut;
            string stdError;
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            int exitCode;

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                using (var tempDir = new DisposableDir())
                {
                    var appPath = Path.Combine(tempDir, "ResourcesTestProjects", "ReadFromResources");
                    TestUtils.CopyFolder(Path.Combine(TestUtils.GetMiscProjectsFolder(), "ResourcesTestProjects", "ReadFromResources"), appPath);
                    var workingDir = Path.Combine(appPath, "src", "ResourcesLibrary");

                    var environment = new Dictionary<string, string> { { "DNX_TRACE", "0" } };
                    DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        "restore", "",
                        out stdOut,
                        out stdError,
                        environment: null,
                        workingDir: workingDir);
                    exitCode = DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        "pack",
                        "",
                        out stdOut,
                        out stdError,
                        environment,
                        workingDir);

                    Assert.Empty(stdError);
                    Assert.Equal(0, exitCode);
                    Assert.True(Directory.Exists(Path.Combine(workingDir, "bin")));
                    Assert.True(File.Exists(Path.Combine(workingDir, "bin", "Debug", "dnx451", "fr-FR", "ResourcesLibrary.resources.dll")));
                    Assert.True(File.Exists(Path.Combine(workingDir, "bin", "Debug", "dnxcore50", "fr-FR", "ResourcesLibrary.resources.dll")));
                }
            }
        }
Example #27
0
        public void DnuPack_ShowUnresolvedDependencyWhenBuildFails(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            var projectJson = @"{
              ""frameworks"": {
            ""dnx451"": {
              ""dependencies"": {
              ""NonexistentPackage"": ""1.0.0""
              }
            }
              }
            }";

            using (var tempDir = new DisposableDir())
            {
                var projectPath = Path.Combine(tempDir, "Project");
                var emptyLocalFeed = Path.Combine(tempDir, "EmptyLocalFeed");
                Directory.CreateDirectory(projectPath);
                Directory.CreateDirectory(emptyLocalFeed);
                var projectJsonPath = Path.Combine(projectPath, Runtime.Project.ProjectFileName);
                File.WriteAllText(projectJsonPath, projectJson);

                string stdOut, stdErr;
                var exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    "restore",
                    $"{projectJsonPath} -s {emptyLocalFeed}",
                    out stdOut,
                    out stdErr);
                Assert.NotEqual(0, exitCode);

                exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    "pack",
                    projectJsonPath,
                    out stdOut,
                    out stdErr);

                Assert.NotEqual(0, exitCode);
                Assert.NotEmpty(stdErr);
                var unresolvedDependencyErrorCount = stdErr
                    .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(line => line.Contains("The dependency NonexistentPackages >= 1.0.0 could not be resolved"))
                    .Count();
                Assert.Equal(1, unresolvedDependencyErrorCount);
            }
        }
Example #28
0
        public void ProjectResolverDoesNotThrowWhenThereAreDuplicatedEntriesInGlobalJson()
        {
            const string unambiguousName = "ProjectA";
            var solutionStructure = @"{
              'global.json': '',
              'src': {
            'ProjectA': {
              'project.json': '{}'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src"", ""src/../src"", ""somedir\\somesubdir\\..\\..\\src""]
            }")
                    .WriteTo(solutionPath);

                var unambiguousProjectPath = Path.Combine(solutionPath, "src", unambiguousName);

                Project project;
                Assert.True(new ProjectResolver(unambiguousProjectPath).TryResolveProject(unambiguousName, out project));
                Assert.NotNull(project);
            }
        }
Example #29
0
        public void AppHostShowsErrorWhenCurrentTargetFrameworkWasNotFoundInProjectJson(string flavor, string os, string architecture)
        {
            var runtimeTargetFrameworkString = flavor == "coreclr" ? FrameworkNames.LongNames.DnxCore50 : FrameworkNames.LongNames.Dnx451;
            var runtimeTargetFramework = new FrameworkName(runtimeTargetFrameworkString);
            var runtimeTargetFrameworkShortName = VersionUtility.GetShortFrameworkName(runtimeTargetFramework);
            var runtimeType = flavor == "coreclr" ? "CoreCLR" : "CLR";
            runtimeType = RuntimeEnvironmentHelper.IsMono ? "Mono" : runtimeType;
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            var projectJsonContents = @"{
              ""frameworks"": {
            ""FRAMEWORK_NAME"": { }
              }
            }".Replace("FRAMEWORK_NAME", flavor == "coreclr" ? "dnx451" : "dnxcore50");

            using (runtimeHomeDir)
            using (var projectPath = new DisposableDir())
            {
                var projectName = new DirectoryInfo(projectPath).Name;
                var projectJsonPath = Path.Combine(projectPath, Project.ProjectFileName);
                File.WriteAllText(projectJsonPath, projectJsonContents);

                string stdOut, stdErr;
                var exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: $"run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    workingDir: projectPath);

                // TODO: add complete error message check when OS version information is consistent on CoreCLR and CLR
                var expectedErrorMsg = $@"The current runtime target framework is not compatible with '{projectName}'.";

                Assert.NotEqual(0, exitCode);
                Assert.Contains(expectedErrorMsg, stdErr);
            }
        }
Example #30
0
        public void ProjectResolverDoesNotThrowWhenAmbiguousNameIsNotUsed()
        {
            const string ambiguousName = "ProjectA";
            const string unambiguousName = "ProjectB";
            var solutionStructure = @"{
              'global.json': '',
              'src1': {
            'ProjectA': {
              'project.json': '{}'
            },
            'ProjectB': {
              'project.json': '{}'
            }
              },
              'src2': {
            'ProjectA': {
              'project.json': '{}'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src1"", ""src2""]
            }")
                    .WriteTo(solutionPath);

                var ambiguousProjectPath = Path.Combine(solutionPath, "src1", ambiguousName);
                var unambiguousProjectPath = Path.Combine(solutionPath, "src1", unambiguousName);

                Project project;
                Assert.True(new ProjectResolver(ambiguousProjectPath).TryResolveProject(unambiguousName, out project));
                Assert.NotNull(project);

                project = null;
                Assert.True(new ProjectResolver(unambiguousProjectPath).TryResolveProject(unambiguousName, out project));
                Assert.NotNull(project);
            }
        }
Example #31
0
        public void ProjectResolverWorksWithMultipleNonProjectFoldersThatHaveSameName()
        {
            const string projectName = "ProjectA";
            var solutionStructure = @"{
              'global.json': '',
              'src1': {
            'ProjectA': {
              'file.txt': 'Not a project.json'
            }
              },
              'src2': {
            'ProjectA': {
              'file.txt': 'Not a project.json'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src1"", ""src2""]
            }")
                    .WriteTo(solutionPath);

                var projectPath = Path.Combine(solutionPath, "src1", projectName);

                Project project;
                Assert.False(new ProjectResolver(projectPath).TryResolveProject(projectName, out project));
                Assert.Null(project);
            }
        }
Example #32
0
        public void AppHostShowsErrorWhenNoProjectJsonWasFound(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var emptyFolder = new DisposableDir())
            {
                string stdOut, stdErr;
                var exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    workingDir: emptyFolder);

                Assert.NotEqual(0, exitCode);
                Assert.Contains("Unable to resolve project", stdErr);
            }
        }
Example #33
0
        public void DnuRestore_GeneratesDefaultRuntimeTargets(string flavor, string os, string architecture)
        {
            // TODO(anurse): Maybe this could be a condition? This is the only place we need it right now so it
            // didn't seem worth the refactor.
            if (RuntimeEnvironmentHelper.RuntimeEnvironment.OperatingSystem.Equals("Darwin"))
            {
                var ver = Version.Parse(RuntimeEnvironmentHelper.RuntimeEnvironment.OperatingSystemVersion);
                if (ver < new Version(10, 10))
                {
                    // Not supported on this!
                    return;
                }
            }

            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            LockFile lockFile;
            using (var testDir = new DisposableDir())
            {
                var misc = TestUtils.GetMiscProjectsFolder();
                DirTree.CreateFromDirectory(Path.Combine(misc, "RuntimeRestore", "TestProject"))
                    .WriteTo(testDir);

                // Clean up the lock file if it ended up there during the copy
                var lockFilePath = Path.Combine(testDir, "project.lock.json");
                if (File.Exists(lockFilePath))
                {
                    File.Delete(lockFilePath);
                }

                // Restore the project!
                var source = Path.Combine(misc, "RuntimeRestore", "RuntimeRestoreTestPackage", "feed");
                DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", $"--source {source}", workingDir: testDir);

                // Check the lock file
                lockFile = (new LockFileFormat()).Read(Path.Combine(testDir, "project.lock.json"));
            }

            // We can use the runtime environment to determine the expected RIDs because by default it only uses the current OSes RIDs
            if (RuntimeEnvironmentHelper.IsWindows)
            {
                AssertLockFileTarget(lockFile, "win7-x86", "win7-x86");
                AssertLockFileTarget(lockFile, "win7-x64", "win7-x64");
            }
            else
            {
                var osName = RuntimeEnvironmentHelper.RuntimeEnvironment.GetDefaultRestoreRuntimes().First();
                osName = osName.Substring(0, osName.Length - 4); // Remove the -x86 suffix
                AssertLockFileTarget(lockFile, osName + "-x86", assemblyRid: null); // There is no ubuntu/osx-x86 in the test package
                AssertLockFileTarget(lockFile, osName + "-x64", osName + "-x64");
            }
        }