fix integration tests
[mcs.git] / tools / linker / Tests / Mono.Linker.Tests / IntegrationTestFixture.cs
blobf455f6559af21a7197821079338764634b312458
1 //
2 // IntegrationTestFixture.cs
3 //
4 // Author:
5 // Jb Evain (jbevain@novell.com)
6 //
7 // (C) 2007 Novell, Inc.
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 using System;
30 using System.Diagnostics;
31 using System.IO;
32 using Mono.Linker.Steps;
33 using NUnit.Framework;
35 namespace Mono.Linker.Tests {
37 [TestFixture]
38 public class IntegrationTestFixture : AbstractTestFixture {
40 [SetUp]
41 public override void SetUp ()
43 base.SetUp ();
45 TestCasesRoot = "Integration";
48 [Test]
49 public void TestHelloWorld ()
51 RunTest ("HelloWorld");
54 [Test]
55 public void TestCrypto ()
57 RunTest ("Crypto");
60 protected override LinkContext GetContext()
62 LinkContext context = base.GetContext ();
63 context.CoreAction = AssemblyAction.Link;
64 return context;
67 protected override Pipeline GetPipeline ()
69 Pipeline p = new Pipeline ();
70 p.AppendStep (new LoadReferencesStep ());
71 p.AppendStep (new BlacklistStep ());
72 p.AppendStep (new TypeMapStep ());
73 p.AppendStep (new MarkStep ());
74 p.AppendStep (new SweepStep ());
75 p.AppendStep (new CleanStep ());
76 p.AppendStep (new OutputStep ());
77 return p;
80 protected override void RunTest (string testCase)
82 if (!OnMono ())
83 Assert.Ignore ("Integration tests are only runnable on Mono");
85 base.RunTest (testCase);
86 string test = Path.Combine (GetTestCasePath (), "Test.exe");
88 string original = Execute (GetTestCasePath (), "Test.exe");
90 Pipeline.PrependStep (
91 new ResolveFromAssemblyStep (
92 test));
94 Run ();
96 string linked = Execute (Context.OutputDirectory, "Test.exe");
98 Assert.AreEqual (original, linked);
101 static bool OnMono ()
103 return Type.GetType ("System.MonoType") != null;
106 static string Execute (string directory, string file)
108 Process p = new Process ();
109 p.StartInfo.EnvironmentVariables ["MONO_PATH"] = directory;
110 p.StartInfo.CreateNoWindow = true;
111 p.StartInfo.WorkingDirectory = directory;
112 p.StartInfo.FileName = "mono";
113 p.StartInfo.Arguments = file;
114 p.StartInfo.RedirectStandardOutput = true;
115 p.StartInfo.UseShellExecute = false;
117 p.Start ();
118 p.WaitForExit ();
120 return p.StandardOutput.ReadToEnd ();