Example #1
0
        private static int RunTest(HostEnvironment hostEnvironment, string suiteName, string test, StringBuilder actualOutput, List <string> compilerParameters, List <string> testCaseParameters)
        {
            hostEnvironment.hasError = false;
            IName                     name               = hostEnvironment.NameTable.GetNameFor(suiteName);
            SpecSharpOptions          options            = new SpecSharpOptions(); //TODO: extract from params
            List <IAssemblyReference> assemblyReferences = new List <IAssemblyReference>();
            List <IModuleReference>   moduleReferences   = new List <IModuleReference>();

            assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
            IUnit unit;
            SpecSharpAssembly /*?*/    assem = null;
            SpecSharpCompilationHelper helper;

            if (hostEnvironment.previousDocument != null && compilerParameters.Contains("/incremental"))
            {
                unit   = hostEnvironment.GetIncrementalUnit(test);
                helper = (SpecSharpCompilationHelper)hostEnvironment.previousDocument.SpecSharpCompilationPart.Helper;
            }
            else
            {
                List <SpecSharpSourceDocument> programSources = new List <SpecSharpSourceDocument>(1);
                assem  = new SpecSharpAssembly(name, "", hostEnvironment, options, assemblyReferences, moduleReferences, programSources);
                helper = new SpecSharpCompilationHelper(assem.Compilation);
                programSources.Add(hostEnvironment.previousDocument = new SpecSharpSourceDocument(helper, name, "", test));
                unit = assem;
            }
            if (assem != null && assem.Compilation.HasErrors)
            {
                return(0);
            }
            if (assem != null && assem.EntryPoint.ResolvedMethod != Dummy.Method)
            {
                var memStream = new MemoryStream();
                PeWriter.WritePeToStream(assem, hostEnvironment, memStream);
                if (hostEnvironment.hasError)
                {
                    return(0);
                }
                var runtimeAssembly = System.Reflection.Assembly.Load(memStream.ToArray());
                var result          = runtimeAssembly.EntryPoint.Invoke(null, null);
                if (result is int)
                {
                    return((int)result);
                }
                return(0);
            }

            BaseCodeTraverser traverser = new BaseCodeTraverser();

            unit.Dispatch(traverser);
            return(0);
        }
Example #2
0
 private static List<IAssemblyReference> GetAssemblyReferences(SpecSharpOptions commandLineOptions, HostEnvironment hostEnvironment) {
   List<IAssemblyReference> assemblyReferences = new List<IAssemblyReference>();
   assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
   foreach (string assemblyReference in commandLineOptions.ReferencedAssemblies) {
     IUnit unit = hostEnvironment.LoadUnitFrom(assemblyReference);
     if (unit == Dummy.Unit) {
       unit = hostEnvironment.LoadUnitFrom(Path.Combine(Path.GetDirectoryName(typeof(object).Assembly.Location), assemblyReference));
     }
     IAssembly/*?*/ aref = unit as IAssembly;
     if (aref != null)
       assemblyReferences.Add(aref);
     else {
       //TODO: error message
     }
   }
   return assemblyReferences;
 }
Example #3
0
        private static List <IAssemblyReference> GetAssemblyReferences(SpecSharpOptions commandLineOptions, HostEnvironment hostEnvironment)
        {
            List <IAssemblyReference> assemblyReferences = new List <IAssemblyReference>();

            assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
            foreach (string assemblyReference in commandLineOptions.ReferencedAssemblies)
            {
                IUnit unit = hostEnvironment.LoadUnitFrom(assemblyReference);
                if (unit == Dummy.Unit)
                {
                    unit = hostEnvironment.LoadUnitFrom(Path.Combine(Path.GetDirectoryName(typeof(object).Assembly.Location), assemblyReference));
                }
                IAssembly /*?*/ aref = unit as IAssembly;
                if (aref != null)
                {
                    assemblyReferences.Add(aref);
                }
                else
                {
                    //TODO: error message
                }
            }
            return(assemblyReferences);
        }
Example #4
0
    private static int RunTest(HostEnvironment hostEnvironment, string suiteName, string test, StringBuilder actualOutput, List<string> compilerParameters, List<string> testCaseParameters) {
      hostEnvironment.hasError = false;
      IName name = hostEnvironment.NameTable.GetNameFor(suiteName);
      SpecSharpOptions options = new SpecSharpOptions(); //TODO: extract from params
      List<IAssemblyReference> assemblyReferences = new List<IAssemblyReference>();
      List<IModuleReference> moduleReferences = new List<IModuleReference>();
      assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
      IUnit unit;
      SpecSharpAssembly/*?*/ assem = null;
      SpecSharpCompilationHelper helper;
      if (hostEnvironment.previousDocument != null && compilerParameters.Contains("/incremental")) {
        unit = hostEnvironment.GetIncrementalUnit(test);
        helper = (SpecSharpCompilationHelper)hostEnvironment.previousDocument.SpecSharpCompilationPart.Helper;
      } else {
        List<SpecSharpSourceDocument> programSources = new List<SpecSharpSourceDocument>(1);
        assem = new SpecSharpAssembly(name, "", hostEnvironment, options, assemblyReferences, moduleReferences, programSources);
        helper = new SpecSharpCompilationHelper(assem.Compilation);
        programSources.Add(hostEnvironment.previousDocument = new SpecSharpSourceDocument(helper, name, "", test));
        unit = assem;
      }
      if (assem != null && assem.Compilation.HasErrors) return 0;
      if (assem != null && assem.EntryPoint.ResolvedMethod != Dummy.Method) {
        var memStream = new MemoryStream();
        PeWriter.WritePeToStream(assem, hostEnvironment, memStream);
        if (hostEnvironment.hasError) return 0;
        var runtimeAssembly = System.Reflection.Assembly.Load(memStream.ToArray());
        var result = runtimeAssembly.EntryPoint.Invoke(null, null);
        if (result is int) return (int)result;
        return 0;
      }

      BaseCodeTraverser traverser = new BaseCodeTraverser();
      unit.Dispatch(traverser);
      return 0;
    }