Beispiel #1
0
        private TestCaseSandbox Sandbox(TestCase testCase, TestCaseCompilationMetadataProvider metadataProvider)
        {
            var sandbox = _factory.CreateSandbox(testCase);

            sandbox.Populate(metadataProvider);
            return(sandbox);
        }
Beispiel #2
0
        private ManagedCompilationResult Compile(TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider 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));
        }
Beispiel #3
0
        public virtual void Populate(TestCaseCompilationMetadataProvider 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 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));
                }
            }
        }
Beispiel #4
0
 public TestCaseCompiler(TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider metadataProvider, ILInputCompiler ilCompiler)
 {
     _ilCompiler       = ilCompiler;
     _sandbox          = sandbox;
     _metadataProvider = metadataProvider;
 }
Beispiel #5
0
 public TestCaseCompiler(TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider metadataProvider)
     : this(sandbox, metadataProvider, new ILInputCompiler())
 {
 }
Beispiel #6
0
 public virtual TestCaseCompiler CreateCompiler(TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider metadataProvider)
 {
     return(new TestCaseCompiler(sandbox, metadataProvider));
 }