public void WriteInstrumentedTestCode(LanguageSupport mode, FileInfo inFileInfo) { var relativePath = ParaibaPath.GetRelativePath(inFileInfo.FullName, BaseDirInfo.FullName); var outFileInfo = OutDirInfo.GetFile(relativePath); var code = InstrumentTestCase(mode, inFileInfo, BaseDirInfo); outFileInfo.Directory.Create(); File.WriteAllText(outFileInfo.FullName, code); }
public static string InsertInstrumentationCode(LanguageSupport mode, string fileName) { var info = new CoverageInfo( Fixture.GetCoverageInputPath(), mode.Name, SharingMethod.SharedMemory); var inPath = Path.Combine(Fixture.GetCoverageInputPath(), fileName); var code = OccfCodeGenerator.GetCoveragedCode(new FileInfo(inPath), info, mode); File.WriteAllText(Fixture.GetOutputPath(fileName), code); return code; }
public static void VerifyCodeInsertion(LanguageSupport mode, string fileName) { var code = InsertInstrumentationCode(mode, fileName); var expPath = Path.Combine(Fixture.GetCoverageExpectationPath(), fileName); using (var reader = new StreamReader(expPath)) { var expected = reader.ReadToEnd(); Assert.That(code, Is.EqualTo(expected)); } }
public static string GetIdentifiedTest( FileInfo testFile, TestInfo info, LanguageSupport support, out string relativePath) { relativePath = ParaibaPath.GetRelativePath(testFile.FullName, info.BasePath); var ast = support.CodeToXml.GenerateFromFile(testFile.FullName); // テストケース識別用コードの埋め込み CodeTransformer.InsertIntoTestCase(info, ast, support, relativePath); // コード生成 return support.XmlToCode.Generate(ast); }
public static string GetCoveragedCode( FileInfo codeFile, CoverageInfo info, LanguageSupport support, out string relativePath) { relativePath = ParaibaPath.GetRelativePath(codeFile.FullName, info.BasePath); var ast = support.CodeToXml.GenerateFromFile(codeFile.FullName); // 測定用コードの埋め込み var path = relativePath; CodeTransformer.InstrumentStatementAndPredicate(info, ast, support, path); // コード生成 return support.XmlToCode.Generate(ast); }
private static void WriteTestCodeFiles( DirectoryInfo rootDir, DirectoryInfo testDir, LanguageSupport prof, TestInfo info) { var paths = prof.FilePatterns.SelectMany( pattern => testDir.EnumerateFiles( pattern, SearchOption.AllDirectories)); foreach (var path in paths.ToList()) { var backPath = Path.Combine(rootDir.FullName, path.FullName + OccfNames.BackupSuffix); path.CopyTo(backPath, true); //バックアップファイルの上書き可 var outPath = OccfCodeGenerator.AnalyzeAndWriteIdentifiedTest(prof, info, path, rootDir); Console.WriteLine("wrote:" + outPath); } }
private static void WriteProductionCodeFiles( DirectoryInfo rootDir, IEnumerable<FileInfo> fileInfos, LanguageSupport mode, CoverageInfo info) { foreach (var path in fileInfos) { // 対象ファイルに対してKlee_backやLine_backがあるときは作成しない // Avoid ge if (!(File.Exists(path.FullName + OccfNames.LineBackUpSuffix)) && !(File.Exists(path.FullName + OccfNames.KleeBackUpSuffix))) { var backPath = Path.Combine(rootDir.FullName, path.FullName + OccfNames.BackupSuffix); path.CopyTo(backPath, true); } var outPath = OccfCodeGenerator.WriteCoveragedCode(mode, info, path, rootDir); Console.WriteLine("wrote:" + outPath); } }
public static void InsertMeasurementCode( DirectoryInfo rootDir, ICollection<FileInfo> fileInfos, DirectoryInfo testDir, DirectoryInfo libDir, LanguageSupport mode, RecordingMode recordingMode) { Contract.Requires<ArgumentException>(rootDir.Exists); Contract.Requires<ArgumentException>(testDir == null || testDir.Exists); Contract.Requires<ArgumentException>(libDir.Exists); Contract.Requires<ArgumentNullException>(mode != null); //root var covInfo = new CoverageInfo(rootDir.FullName, mode.Name, SharingMethod.File); //(o)root or src? var testInfo = testDir != null ? new TestInfo(rootDir.FullName) : null; //root RemoveExistingCoverageDataFiles(rootDir, libDir); mode.RemoveLibraries(libDir); //+src WriteProductionCodeFiles(rootDir, fileInfos, mode, covInfo); if (testInfo != null) { //(o)root or src WriteTestCodeFiles(rootDir, testDir, mode, testInfo); } else { // Initialize test information with empty contents testInfo = new TestInfo(rootDir.FullName); testInfo.TestCases.Add(new TestCase("nothing", "nothing", new CodeRange())); } //root WriteInfoFiles(rootDir, covInfo, testInfo); mode.CopyLibraries(libDir, recordingMode); }
public static string GetCoveragedCode( FileInfo codeFile, CoverageInfo info, LanguageSupport support) { string relativePath; return GetCoveragedCode(codeFile, info, support, out relativePath); }
public static string WriteCoveragedCode( LanguageSupport support, CoverageInfo info, FileInfo codeFile, DirectoryInfo outDir) { string relativePath; var code = GetCoveragedCode(codeFile, info, support, out relativePath); return WriteCode(relativePath, outDir, code); }
public static string GetIdentifiedTest(FileInfo testFile, TestInfo info, LanguageSupport support) { string relativePath; return GetIdentifiedTest(testFile, info, support, out relativePath); }
public static string AnalyzeAndWriteIdentifiedTest( LanguageSupport support, TestInfo info, FileInfo fullPath, DirectoryInfo outDirPath) { string relativePath; var code = GetIdentifiedTest(fullPath, info, support, out relativePath); return WriteCode(relativePath, outDirPath, code); }