コード例 #1
0
        /// <summary>
        ///   Compiles the <paramref name="compilation" /> with the S# compiler and returns the resulting assembly that has been
        ///   loaded into the app domain.
        /// </summary>
        /// <param name="compilation">The compilation that should be compiled.</param>
        /// <param name="output">The output that should be used to write test output.</param>
        public static Assembly CompileSafetySharp(Compilation compilation, TestTraceOutput output)
        {
            using (var workspace = new AdhocWorkspace())
            {
                var project = workspace
                              .AddProject(compilation.AssemblyName, LanguageNames.CSharp)
                              .AddMetadataReferences(compilation.References)
                              .WithCompilationOptions(compilation.Options);

                foreach (var syntaxTree in compilation.SyntaxTrees)
                {
                    project = project.AddDocument(syntaxTree.FilePath, syntaxTree.GetRoot().GetText(Encoding.UTF8)).Project;
                }

                var errorReporter = new TestErrorReporter(output);
                var compiler      = new Compiler(errorReporter);

                try
                {
                    var assembly = compiler.Compile(project);
                    output.Trace("{0}", SyntaxTreesToString(compiler.Compilation));

                    return(assembly);
                }
                catch (CompilationException e)
                {
                    throw new TestException("{0}\n\n{1}", e.Message, SyntaxTreesToString(compiler.Compilation));
                }
            }
        }
コード例 #2
0
ファイル: TestModel.cs プロジェクト: cubeme/safety-sharp
		/// <summary>
		///     Executes the tests of the object.
		/// </summary>
		/// <param name="output">The output that should be used to write test output.</param>
		public void Test(TestTraceOutput output)
		{
			Output = output;

			Seal();
			Metadata.Model.ShouldBe(this);

			Check();
		}
コード例 #3
0
ファイル: TestComponent.cs プロジェクト: cubeme/safety-sharp
		/// <summary>
		///     Executes the tests of the object.
		/// </summary>
		/// <param name="output">The output that should be used to write test output.</param>
		public void Test(TestTraceOutput output)
		{
			Output = output;

			MetadataBuilder.FinalizeMetadata();
			Metadata.Component.ShouldBe(this);

			Check();
		}
コード例 #4
0
ファイル: TestErrorReporter.cs プロジェクト: cubeme/ssharp
 public TestErrorReporter(TestTraceOutput output)
 {
     _output = output;
 }
コード例 #5
0
 /// <summary>
 ///   Initializes a new instance.
 /// </summary>
 /// <param name="output">The stream that should be used to write the test output.</param>
 public Tests(ITestOutputHelper output = null)
 {
     Output = new TestTraceOutput(output);
 }
コード例 #6
0
        /// <summary>
        ///   Compiles the <paramref name="code" />, instantiates all non-abstract classes implementing
        ///   <see cref="ModelBase" />, and returns them.
        /// </summary>
        /// <param name="code">The code that should be compiled.</param>
        /// <param name="output">The output that should be used to write test output.</param>
        public static IEnumerable <ModelBase> GetModelBases(string code, TestTraceOutput output)
        {
            var syntaxTree = SyntaxFactory.ParseSyntaxTree(code, path: ".", encoding: Encoding.UTF8);

            return(GetModelBases(syntaxTree, output));
        }
コード例 #7
0
        /// <summary>
        ///   Compiles the <paramref name="syntaxTree" />, instantiates all non-abstract classes implementing
        ///   <see cref="ModelBase" />, and returns them.
        /// </summary>
        /// <param name="syntaxTree">The syntax tree that should be compiled.</param>
        /// <param name="output">The output that should be used to write test output.</param>
        protected static IEnumerable <ModelBase> GetModelBases(SyntaxTree syntaxTree, TestTraceOutput output)
        {
            var compilation   = CreateCompilation(syntaxTree);
            var semanticModel = compilation.GetSemanticModel(syntaxTree);

            var testableTypes = syntaxTree
                                .Descendants <ClassDeclarationSyntax>()
                                .Select(declaration => declaration.GetTypeSymbol(semanticModel))
                                .Where(symbol => !symbol.IsGenericType && !symbol.IsAbstract && symbol.ContainingType == null)
                                .Where(symbol => symbol.IsDerivedFrom(semanticModel.GetTypeSymbol <ModelBase>()))
                                .Select(symbol => symbol.ToDisplayString())
                                .ToArray();

            if (testableTypes.Length == 0)
            {
                throw new TestException("Unable to find any ModelBase declarations.");
            }

            var assembly = CompileSafetySharp(compilation, output);

            return(testableTypes.Select(testableType => (ModelBase)Activator.CreateInstance(assembly.GetType(testableType))));
        }
コード例 #8
0
        /// <summary>
        ///   Compiles the <paramref name="code" />, instantiates all non-abstract classes implementing
        ///   <see cref="ITestableObject" />, and returns them.
        /// </summary>
        /// <param name="code">The code that should be compiled.</param>
        /// <param name="output">The output that should be used to write test output.</param>
        public static IEnumerable <ITestableObject> GetTestableObjects(string code, TestTraceOutput output)
        {
            var syntaxTree = SyntaxFactory.ParseSyntaxTree(code, encoding: Encoding.UTF8);

            return(GetTestableObjects(syntaxTree, output));
        }
コード例 #9
0
ファイル: TestModel.cs プロジェクト: pascalpfeil/ssharp
 public static SafetySharpRuntimeModel CreateRuntimeModel(TestTraceOutput output)
 {
     return(SafetySharpRuntimeModel.Create(CreateEmptyModel(output)));
 }
コード例 #10
0
ファイル: TestModel.cs プロジェクト: pascalpfeil/ssharp
 public static ModelBase CreateEmptyModel(TestTraceOutput output)
 {
     return(Tests.GetModelBases(EmptyTestModel, output).First());
 }
コード例 #11
0
		public TestErrorReporter(TestTraceOutput output)
		{
			_output = output;
		}
コード例 #12
0
ファイル: Tests.cs プロジェクト: isse-augsburg/ssharp
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="output">The stream that should be used to write the test output.</param>
		public Tests(ITestOutputHelper output = null)
		{
			Output = new TestTraceOutput(output);
		}
コード例 #13
0
ファイル: Tests.cs プロジェクト: isse-augsburg/ssharp
		/// <summary>
		///   Compiles the <paramref name="compilation" /> with the S# compiler and returns the resulting assembly that has been
		///   loaded into the app domain.
		/// </summary>
		/// <param name="compilation">The compilation that should be compiled.</param>
		/// <param name="output">The output that should be used to write test output.</param>
		public static Assembly CompileSafetySharp(Compilation compilation, TestTraceOutput output)
		{
			using (var workspace = new AdhocWorkspace())
			{
				var project = workspace
					.AddProject(compilation.AssemblyName, LanguageNames.CSharp)
					.AddMetadataReferences(compilation.References)
					.WithCompilationOptions(compilation.Options);

				foreach (var syntaxTree in compilation.SyntaxTrees)
					project = project.AddDocument(syntaxTree.FilePath, syntaxTree.GetRoot().GetText(Encoding.UTF8)).Project;

				var errorReporter = new TestErrorReporter(output);
				var compiler = new Compiler(errorReporter);

				try
				{
					var assembly = compiler.Compile(project);
					output.Trace("{0}", SyntaxTreesToString(compiler.Compilation));

					return assembly;
				}
				catch (CompilationException e)
				{
					throw new TestException("{0}\n\n{1}", e.Message, SyntaxTreesToString(compiler.Compilation));
				}
			}
		}
コード例 #14
0
		public CSharpErrorReporter(TestTraceOutput output)
		{
			_output = output;
		}
コード例 #15
0
ファイル: TestObject.cs プロジェクト: cubeme/safety-sharp
		/// <summary>
		///     Executes the tests of the object.
		/// </summary>
		/// <param name="output">The output that should be used to write test output.</param>
		public void Test(TestTraceOutput output)
		{
			Output = output;
			Check();
		}
コード例 #16
0
ファイル: TestComponent.cs プロジェクト: isse-augsburg/ssharp
		/// <summary>
		///   Executes the tests of the object.
		/// </summary>
		/// <param name="output">The output that should be used to write test output.</param>
		/// <param name="args">The arguments passed to the test object.</param>
		public void Test(TestTraceOutput output, object[] args)
		{
			Output = output;
			Check();
		}
コード例 #17
0
ファイル: TestTraceOutput.cs プロジェクト: pascalpfeil/ssharp
 internal TestTraceOutputTextWriterAdapter(TestTraceOutput adaptTo, bool trace)
 {
     _adaptTo = adaptTo;
     _trace   = trace;
 }
コード例 #18
0
ファイル: TestComponent.cs プロジェクト: cubeme/ssharp
 /// <summary>
 ///   Executes the tests of the object.
 /// </summary>
 /// <param name="output">The output that should be used to write test output.</param>
 /// <param name="args">The arguments passed to the test object.</param>
 public void Test(TestTraceOutput output, object[] args)
 {
     Output = output;
     Check();
 }