Ejemplo n.º 1
0
        public virtual void Populate(TestCaseMetadaProvider metadataProvider)
        {
            _testCase.SourceFile.Copy(_directory);

            if (_testCase.HasLinkXmlFile)
            {
                _testCase.LinkXmlFile.Copy(InputDirectory);
            }

            CopyToInputAndExpectations(GetExpectationsAssemblyPath());

            foreach (var dep in metadataProvider.AdditionalFilesToSandbox())
            {
                dep.Source.FileMustExist().Copy(_directory.Combine(dep.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetResources())
            {
                res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName));
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore())
            {
                var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter())
            {
                var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);
            }
        }
Ejemplo n.º 2
0
        private TestCaseSandbox Sandbox(TestCase testCase, TestCaseMetadaProvider metadataProvider)
        {
            var sandbox = _factory.CreateSandbox(testCase);

            sandbox.Populate(metadataProvider);
            return(sandbox);
        }
Ejemplo n.º 3
0
        protected virtual LinkerCustomizations CustomizeLinker(LinkerDriver linker, TestCaseMetadaProvider metadataProvider)
        {
            LinkerCustomizations customizations = new LinkerCustomizations();

            metadataProvider.CustomizeLinker(linker, customizations);

            return(customizations);
        }
Ejemplo n.º 4
0
 public LinkedTestCaseResult(TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadaProvider metadaProvider, ManagedCompilationResult compilationResult)
 {
     TestCase                 = testCase;
     InputAssemblyPath        = inputAssemblyPath;
     OutputAssemblyPath       = outputAssemblyPath;
     ExpectationsAssemblyPath = expectationsAssemblyPath;
     Sandbox           = sandbox;
     MetadataProvider  = metadaProvider;
     CompilationResult = compilationResult;
 }
Ejemplo n.º 5
0
 public LinkedTestCaseResult(TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadaProvider metadaProvider, ManagedCompilationResult compilationResult, LinkerTestLogger logger, LinkerCustomizations customizations)
 {
     TestCase                 = testCase;
     InputAssemblyPath        = inputAssemblyPath;
     OutputAssemblyPath       = outputAssemblyPath;
     ExpectationsAssemblyPath = expectationsAssemblyPath;
     Sandbox           = sandbox;
     MetadataProvider  = metadaProvider;
     CompilationResult = compilationResult;
     Logger            = logger;
     Customizations    = customizations;
 }
Ejemplo n.º 6
0
        private ManagedCompilationResult Compile(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider)
        {
            var compiler    = _factory.CreateCompiler();
            var sourceFiles = sandbox.SourceFiles.Select(s => s.ToString()).ToArray();

            var references        = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory);
            var inputAssemblyPath = compiler.CompileTestIn(sandbox.InputDirectory, "test.exe", sourceFiles, references, null);

            references = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory);
            var expectationsAssemblyPath = compiler.CompileTestIn(sandbox.ExpectationsDirectory, "test.exe", sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" });

            return(new ManagedCompilationResult(inputAssemblyPath, expectationsAssemblyPath));
        }
Ejemplo n.º 7
0
        public virtual void Populate(TestCaseMetadaProvider metadataProvider)
        {
            _testCase.SourceFile.Copy(_directory);

            if (_testCase.HasLinkXmlFile)
            {
                _testCase.LinkXmlFile.Copy(InputDirectory);
            }

            CopyToInputAndExpectations(GetExpectationsAssemblyPath());

            foreach (var dep in metadataProvider.AdditionalFilesToSandbox())
            {
                var destination = _directory.Combine(dep.DestinationFileName);
                dep.Source.FileMustExist().Copy(destination);

                // In a few niche tests we need to copy pre-built assemblies directly into the input directory.
                // When this is done, we also need to copy them into the expectations directory so that if they are used
                // as references we can still compile the expectations version of the assemblies
                if (destination.Parent == InputDirectory)
                {
                    dep.Source.Copy(ExpectationsDirectory.Combine(destination.RelativeTo(InputDirectory)));
                }
            }

            foreach (var res in metadataProvider.GetResources())
            {
                res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName));
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore())
            {
                var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = BeforeReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.Resources?.Copy(destination);
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter())
            {
                var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = AfterReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.Resources?.Copy(destination);
            }
        }
Ejemplo n.º 8
0
        public virtual void Populate(TestCaseMetadaProvider metadataProvider)
        {
            _testCase.SourceFile.Copy(_directory);

            if (_testCase.HasLinkXmlFile)
            {
                _testCase.LinkXmlFile.Copy(InputDirectory);
            }

            CopyToInputAndExpectations(GetExpectationsAssemblyPath());

            foreach (var dep in metadataProvider.AdditionalFilesToSandbox())
            {
                dep.FileMustExist().Copy(_directory);
            }
        }
Ejemplo n.º 9
0
        private ManagedCompilationResult Compile(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider)
        {
            var compiler    = _factory.CreateCompiler(sandbox, metadataProvider);
            var sourceFiles = sandbox.SourceFiles.Select(s => s.ToString()).ToArray();

            var assemblyName = metadataProvider.GetAssemblyName();

            var references          = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory);
            var resources           = sandbox.ResourceFiles.ToArray();
            var additionalArguments = metadataProvider.GetSetupCompilerArguments().ToArray();
            var inputAssemblyPath   = compiler.CompileTestIn(sandbox.InputDirectory, assemblyName, sourceFiles, references, null, resources, additionalArguments);

            references = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory);
            var expectationsAssemblyPath = compiler.CompileTestIn(sandbox.ExpectationsDirectory, assemblyName, sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" }, resources, additionalArguments);

            return(new ManagedCompilationResult(inputAssemblyPath, expectationsAssemblyPath));
        }
Ejemplo n.º 10
0
        private ManagedCompilationResult Compile(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider)
        {
            var inputCompiler        = _factory.CreateCompiler(sandbox, metadataProvider);
            var expectationsCompiler = _factory.CreateCompiler(sandbox, metadataProvider);
            var sourceFiles          = sandbox.SourceFiles.Select(s => s.ToString()).ToArray();

            var assemblyName = metadataProvider.GetAssemblyName();

            var commonReferences       = metadataProvider.GetCommonReferencedAssemblies(sandbox.InputDirectory).ToArray();
            var mainAssemblyReferences = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory).ToArray();
            var resources           = sandbox.ResourceFiles.ToArray();
            var additionalArguments = metadataProvider.GetSetupCompilerArguments().ToArray();

            var expectationsCommonReferences       = metadataProvider.GetCommonReferencedAssemblies(sandbox.ExpectationsDirectory).ToArray();
            var expectationsMainAssemblyReferences = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory).ToArray();

            var inputTask        = Task.Run(() => inputCompiler.CompileTestIn(sandbox.InputDirectory, assemblyName, sourceFiles, commonReferences, mainAssemblyReferences, null, resources, additionalArguments));
            var expectationsTask = Task.Run(() => expectationsCompiler.CompileTestIn(sandbox.ExpectationsDirectory, assemblyName, sourceFiles, expectationsCommonReferences, expectationsMainAssemblyReferences, new[] { "INCLUDE_EXPECTATIONS" }, resources, additionalArguments));

            NPath inputAssemblyPath        = null;
            NPath expectationsAssemblyPath = null;

            try {
                inputAssemblyPath        = GetResultOfTaskThatMakesNUnitAssertions(inputTask);
                expectationsAssemblyPath = GetResultOfTaskThatMakesNUnitAssertions(expectationsTask);
            } catch (Exception) {
                // If completing the input assembly task threw, we need to wait for the expectations task to complete before continuing
                // otherwise we could set the next test up for a race condition with the expectations compilation over access to the sandbox directory
                if (inputAssemblyPath == null && expectationsAssemblyPath == null)
                {
                    try {
                        expectationsTask.Wait();
                    } catch (Exception) {
                        // Don't care, we want to throw the first exception
                    }
                }

                throw;
            }

            return(new ManagedCompilationResult(inputAssemblyPath, expectationsAssemblyPath));
        }
Ejemplo n.º 11
0
        private LinkedTestCaseResult Link(TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadaProvider metadataProvider)
        {
            var linker             = _factory.CreateLinker();
            var builder            = _factory.CreateLinkerArgumentBuilder();
            var caseDefinedOptions = metadataProvider.GetLinkerOptions();

            builder.AddOutputDirectory(sandbox.OutputDirectory);
            foreach (var linkXmlFile in sandbox.LinkXmlFiles)
            {
                builder.AddLinkXmlFile(linkXmlFile);
            }

            builder.AddSearchDirectory(sandbox.InputDirectory);
            foreach (var extraSearchDir in metadataProvider.GetExtraLinkerSearchDirectories())
            {
                builder.AddSearchDirectory(extraSearchDir);
            }

            builder.ProcessOptions(caseDefinedOptions);

            AddAdditionalLinkOptions(builder, metadataProvider);

            // TODO: Should be overridable
            builder.LinkFromAssembly(compilationResult.InputAssemblyPath.ToString());

            linker.Link(builder.ToArgs());

            return(new LinkedTestCaseResult(testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine(compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath));
        }
Ejemplo n.º 12
0
 public TestCaseCompiler(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider, ILCompiler ilCompiler)
 {
     _ilCompiler       = ilCompiler;
     _sandbox          = sandbox;
     _metadataProvider = metadataProvider;
 }
Ejemplo n.º 13
0
 public TestCaseCompiler(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider)
     : this(sandbox, metadataProvider, new ILCompiler())
 {
 }
Ejemplo n.º 14
0
 public virtual TestCaseCompiler CreateCompiler(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider)
 {
     return(new TestCaseCompiler(sandbox, metadataProvider));
 }
Ejemplo n.º 15
0
        private LinkedTestCaseResult Link(TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadaProvider metadataProvider)
        {
            var linker = _factory.CreateLinker();
            var linkerCustomizations = CustomizeLinker(linker, metadataProvider);

            var builder = _factory.CreateLinkerArgumentBuilder(metadataProvider);

            AddLinkOptions(sandbox, compilationResult, builder, metadataProvider);

            LinkerTestLogger logger = new LinkerTestLogger();

            linker.Link(builder.ToArgs(), linkerCustomizations, logger);

            return(new LinkedTestCaseResult(testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine(compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult, logger, linkerCustomizations));
        }
Ejemplo n.º 16
0
 public virtual LinkerArgumentBuilder CreateLinkerArgumentBuilder(TestCaseMetadaProvider metadataProvider)
 {
     return(new LinkerArgumentBuilder(metadataProvider));
 }
Ejemplo n.º 17
0
        protected virtual void AddLinkOptions(TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadaProvider metadataProvider)
        {
            var caseDefinedOptions = metadataProvider.GetLinkerOptions(sandbox.InputDirectory);

            builder.AddOutputDirectory(sandbox.OutputDirectory);
            foreach (var linkXmlFile in sandbox.LinkXmlFiles)
            {
                builder.AddLinkXmlFile(linkXmlFile);
            }

            foreach (var rspFile in sandbox.ResponseFiles)
            {
                builder.AddResponseFile(rspFile);
            }

            builder.AddSearchDirectory(sandbox.InputDirectory);
            foreach (var extraSearchDir in metadataProvider.GetExtraLinkerSearchDirectories())
            {
                builder.AddSearchDirectory(extraSearchDir);
            }

            builder.ProcessOptions(caseDefinedOptions);

            builder.ProcessTestInputAssembly(compilationResult.InputAssemblyPath);
        }
Ejemplo n.º 18
0
        protected virtual void AddLinkOptions(TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadaProvider metadataProvider)
        {
            var caseDefinedOptions = metadataProvider.GetLinkerOptions(sandbox.InputDirectory);

            builder.AddOutputDirectory(sandbox.OutputDirectory);

            foreach (var rspFile in sandbox.ResponseFiles)
            {
                builder.AddResponseFile(rspFile);
            }

            foreach (var inputReference in sandbox.InputDirectory.Files())
            {
                var ext = inputReference.ExtensionWithDot;
                if (ext == ".dll" || ext == ".exe")
                {
                    builder.AddReference(inputReference);
                }
            }
            var coreAction = caseDefinedOptions.TrimMode ?? "skip";

            foreach (var extraReference in metadataProvider.GetExtraLinkerReferences())
            {
                builder.AddReference(extraReference);
                builder.AddAssemblyAction(coreAction, extraReference.FileNameWithoutExtension);
            }

            builder.ProcessOptions(caseDefinedOptions);

            builder.ProcessTestInputAssembly(compilationResult.InputAssemblyPath);
        }
Ejemplo n.º 19
0
 protected virtual void AddAdditionalLinkOptions(LinkerArgumentBuilder builder, TestCaseMetadaProvider metadataProvider)
 {
 }
Ejemplo n.º 20
0
 public LinkerArgumentBuilder(TestCaseMetadaProvider metadaProvider)
 {
     _metadaProvider = metadaProvider;
 }
Ejemplo n.º 21
0
        public virtual void Populate(TestCaseMetadaProvider metadataProvider)
        {
            _testCase.SourceFile.Copy(_directory);

            if (_testCase.HasLinkXmlFile)
            {
                _testCase.LinkXmlFile.Copy(InputDirectory);
            }

            CopyToInputAndExpectations(GetExpectationsAssemblyPath());

            foreach (var dep in metadataProvider.AdditionalFilesToSandbox())
            {
                var destination = _directory.Combine(dep.DestinationFileName);
                dep.Source.FileMustExist().Copy(destination);

                // In a few niche tests we need to copy pre-built assemblies directly into the input directory.
                // When this is done, we also need to copy them into the expectations directory so that if they are used
                // as references we can still compile the expectations version of the assemblies
                if (destination.Parent == InputDirectory)
                {
                    dep.Source.Copy(ExpectationsDirectory.Combine(destination.RelativeTo(InputDirectory)));
                }
            }

            // Copy non class library dependencies to the sandbox
            foreach (var fileName in metadataProvider.GetReferenceValues())
            {
                if (!fileName.StartsWith("System.", StringComparison.Ordinal) && !fileName.StartsWith("Mono.", StringComparison.Ordinal) && !fileName.StartsWith("Microsoft.", StringComparison.Ordinal))
                {
                    CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(fileName.ToNPath()));
                }
            }

            foreach (var referenceDependency in metadataProvider.GetReferenceDependencies())
            {
                CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(referenceDependency.ToNPath()));
            }

            foreach (var res in metadataProvider.GetResources())
            {
                res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetResponseFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetDescriptorFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetSubstitutionFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetLinkAttributesFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore())
            {
                var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = BeforeReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();

                if (compileRefInfo.Resources == null)
                {
                    continue;
                }

                foreach (var res in compileRefInfo.Resources)
                {
                    res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName));
                }
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter())
            {
                var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = AfterReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();

                if (compileRefInfo.Resources == null)
                {
                    continue;
                }

                foreach (var res in compileRefInfo.Resources)
                {
                    res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName));
                }
            }
        }