fix tests
[mcs.git] / tools / linker / Tests / Mono.Linker.Tests / AbstractTestFixture.cs
blobf4ac2d5a3f0d3928c14dc07b6fc5a583a4526640
1 //
2 // AbstractTestFixture.cs
3 //
4 // Author:
5 // Jb Evain (jbevain@gmail.com)
6 //
7 // (C) 2006 Jb Evain
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 namespace Mono.Linker.Tests {
31 using System;
32 using System.IO;
34 using Mono.Cecil;
36 using NUnit.Framework;
38 public abstract class AbstractTestFixture {
40 string _testCasesRoot;
41 string _testCase;
42 LinkContext _context;
43 Pipeline _pipeline;
45 protected LinkContext Context {
46 get { return _context; }
47 set { _context = value; }
50 protected Pipeline Pipeline {
51 get { return _pipeline; }
52 set { _pipeline = value; }
55 public string TestCasesRoot {
56 get { return _testCasesRoot; }
57 set { _testCasesRoot = value; }
60 public string TestCase {
61 get { return _testCase; }
62 set { _testCase = value; }
65 [SetUp]
66 public virtual void SetUp ()
68 _pipeline = GetPipeline ();
71 [TearDown]
72 public virtual void TearDown ()
76 protected virtual Pipeline GetPipeline ()
78 return new Pipeline ();
81 protected virtual LinkContext GetContext ()
83 LinkContext context = new LinkContext (_pipeline);
84 context.OutputDirectory = GetOutputPath ();
85 context.CoreAction = AssemblyAction.Copy;
86 return context;
89 protected string GetOutputPath ()
91 return Path.Combine (
92 Path.GetTempPath (),
93 _testCase);
96 protected string GetTestCasePath ()
98 return Path.Combine (
99 Path.Combine (
100 #if DEBUG
101 Path.Combine (Environment.CurrentDirectory,
102 Path.Combine ("..", "..")),
103 #else
104 Environment.CurrentDirectory,
105 #endif
106 "TestCases"),
107 Path.Combine (
108 _testCasesRoot,
109 _testCase));
112 protected virtual void RunTest (string testCase)
114 _testCase = testCase;
115 _context = GetContext ();
118 protected virtual void Run ()
120 string cd = Environment.CurrentDirectory;
121 Environment.CurrentDirectory = GetTestCasePath ();
122 try {
123 _pipeline.Process (_context);
124 } finally {
125 Environment.CurrentDirectory = cd;
129 protected static string GetAssemblyFileName (AssemblyDefinition asm)
131 return asm.Name.Name + (asm.Kind == AssemblyKind.Dll ? ".dll" : ".exe");