Esempio n. 1
0
        public void CSharpTrivialMetadataCaching()
        {
            var filelist = new List <string>();

            // Do the following compilation twice.
            // The compiler server API should hold on to the mscorlib bits
            // in memory, but the file tracker should still map that it was
            // touched.
            for (int i = 0; i < 2; i++)
            {
                var source1         = Temp.CreateFile().WriteAllText(HelloWorldCS).Path;
                var touchedDir      = Temp.CreateDirectory();
                var touchedBase     = Path.Combine(touchedDir.Path, "touched");
                var clientDirectory = AppContext.BaseDirectory;

                filelist.Add(source1);
                var outWriter = new StringWriter();
                var cmd       = new CSharpCompilerServer(
                    CompilerServerHost.SharedAssemblyReferenceProvider,
                    responseFile: null,
                    new[] { "/nologo", "/touchedfiles:" + touchedBase, source1 },
                    new BuildPaths(
                        clientDirectory,
                        _baseDirectory,
                        RuntimeEnvironment.GetRuntimeDirectory(),
                        Path.GetTempPath()
                        ),
                    s_libDirectory,
                    new TestAnalyzerAssemblyLoader()
                    );

                List <string> expectedReads;
                List <string> expectedWrites;
                BuildTouchedFiles(
                    cmd,
                    Path.ChangeExtension(source1, "exe"),
                    out expectedReads,
                    out expectedWrites
                    );

                var exitCode = cmd.Run(outWriter);

                Assert.Equal(string.Empty, outWriter.ToString().Trim());
                Assert.Equal(0, exitCode);

                AssertTouchedFilesEqual(expectedReads, expectedWrites, touchedBase);
            }

            foreach (String f in filelist)
            {
                CleanupAllGeneratedFiles(f);
            }
        }
Esempio n. 2
0
        public void TrivialMetadataCaching()
        {
            List <String> filelist = new List <string>();

            // Do the following compilation twice.
            // The compiler server API should hold on to the mscorlib bits
            // in memory, but the file tracker should still map that it was
            // touched.
            for (int i = 0; i < 2; i++)
            {
                var source1     = Temp.CreateFile().WriteAllText(helloWorldCS).Path;
                var touchedDir  = Temp.CreateDirectory();
                var touchedBase = Path.Combine(touchedDir.Path, "touched");

                filelist.Add(source1);
                var outWriter = new StringWriter();
                var cmd       = new CSharpCompilerServer(null,
                                                         new[] { "/nologo", "/touchedfiles:" + touchedBase, source1 },
                                                         baseDirectory,
                                                         libDirectory,
                                                         Path.GetTempPath());

                List <string> expectedReads;
                List <string> expectedWrites;
                BuildTouchedFiles(cmd,
                                  Path.ChangeExtension(source1, "exe"),
                                  out expectedReads,
                                  out expectedWrites);

                var exitCode = cmd.Run(outWriter);

                Assert.Equal(string.Empty, outWriter.ToString().Trim());
                Assert.Equal(0, exitCode);

                AssertTouchedFilesEqual(expectedReads,
                                        expectedWrites,
                                        touchedBase);
            }

            foreach (String f in filelist)
            {
                CleanupAllGeneratedFiles(f);
            }
        }