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); } }
private TestCaseSandbox Sandbox(TestCase testCase, TestCaseMetadaProvider metadataProvider) { var sandbox = _factory.CreateSandbox(testCase); sandbox.Populate(metadataProvider); return(sandbox); }
protected virtual LinkerCustomizations CustomizeLinker(LinkerDriver linker, TestCaseMetadaProvider metadataProvider) { LinkerCustomizations customizations = new LinkerCustomizations(); metadataProvider.CustomizeLinker(linker, customizations); return(customizations); }
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; }
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; }
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)); }
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); } }
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); } }
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)); }
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)); }
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)); }
public TestCaseCompiler(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider, ILCompiler ilCompiler) { _ilCompiler = ilCompiler; _sandbox = sandbox; _metadataProvider = metadataProvider; }
public TestCaseCompiler(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider) : this(sandbox, metadataProvider, new ILCompiler()) { }
public virtual TestCaseCompiler CreateCompiler(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider) { return(new TestCaseCompiler(sandbox, metadataProvider)); }
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)); }
public virtual LinkerArgumentBuilder CreateLinkerArgumentBuilder(TestCaseMetadaProvider metadataProvider) { return(new LinkerArgumentBuilder(metadataProvider)); }
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); }
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); }
protected virtual void AddAdditionalLinkOptions(LinkerArgumentBuilder builder, TestCaseMetadaProvider metadataProvider) { }
public LinkerArgumentBuilder(TestCaseMetadaProvider metadaProvider) { _metadaProvider = metadaProvider; }
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)); } } }