public IEnumerable <IFilter> LearnJava(string fileName) { var profile = LanguageSupports.GetCoverageModeByClassName("Java"); var inPath = Path.Combine(Fixture.GetCoverageInputPath(), fileName); var codeFile = new FileInfo(inPath); var ast = profile.CodeToXml.GenerateFromFile(codeFile.FullName); var accepted = profile.AstAnalyzer.FindStatements(ast).ToList(); var rules = RuleLearner.Learn(new[] { new LearningRecord(ast, accepted) }); return(rules); }
public void LearnC(string fileName) { var profile = LanguageSupports.GetCoverageModeByClassName("C"); var inPath = Path.Combine(Fixture.GetCoverageInputPath(), fileName); var codeFile = new FileInfo(inPath); var ast = profile.CodeToXml.GenerateFromFile(codeFile.FullName); var statements = profile.AstAnalyzer.FindStatements(ast).ToList(); RuleLearner.Learn(new[] { new LearningRecord(ast, statements) }); //var statements2 = rule.Find(ast).ToList(); //Assert.That(statements2.Count, Is.EqualTo(statements.Count)); //Assert.That(statements2, Is.SubsetOf(statements)); }
private static void VerifyMeasureAndLocalize( string inDirPath, string expDirPath, DirectoryInfo outDir, string outDirPath) { var profile = LanguageSupports.GetCoverageModeByClassName("C"); Inserter.InsertMeasurementCode(outDir, new Collection <FileInfo>(), null, outDir, profile, RecordingMode.TextFile); // .cと.hファイルが存在するか Assert.That( File.Exists(Path.Combine(outDirPath, "covman.c")), Is.True); Assert.That( File.Exists(Path.Combine(outDirPath, "covman.h")), Is.True); var covinfo = Path.Combine(outDirPath, OccfNames.CoverageInfo); var testinfo = Path.Combine(outDirPath, OccfNames.TestInfo); var targets = Directory.EnumerateFiles( expDirPath, "*.c", SearchOption.AllDirectories) .Concat( Directory.EnumerateFiles( expDirPath, OccfNames.BackupSuffix, SearchOption.AllDirectories)) .Concat(new[] { covinfo, testinfo }); foreach (var target in targets) { AssertEqualFiles(target, expDirPath, inDirPath); } Compile(outDirPath); RunTest(outDirPath); var ret = BugLocalizer.Run( new[] { outDirPath, Path.Combine(outDirPath, "testresult.txt") }); Assert.That(ret, Is.True); }
public void Should_Insert_Measurement_Code_In_JUnit4_Code(string fileName) { var info = new TestInfo(Fixture.GetTestInputPath()); var inPath = Path.Combine(Fixture.GetTestInputPath(), fileName); var code = OccfCodeGenerator.GetIdentifiedTest( new FileInfo(inPath), info, LanguageSupports.GetCoverageModeByClassName("Java")); var expPath = Path.Combine(Fixture.GetTestExpectationPath(), fileName); using (var reader = new StreamReader(expPath)) { var expected = reader.ReadToEnd(); try { Assert.That(code, Is.EqualTo(expected)); } catch { var path = Fixture.GetOutputPath(fileName); File.WriteAllText(path, code); throw; } } }
private static void Main(string[] args) { var outDirInfo = new DirectoryInfo(@"C:\coverage"); var inputDirInfo = new DirectoryInfo( @"C:\Users\exKAZUu\Projects\UnitMaster\fixture\Java\MinForUnitMaster\src\main" //@"..\..\..\fixture\project\input\GetMid" ); var excludeInDirInfo = new DirectoryInfo(@"..\..\..\fixture\project\input\GetMid\test"); var instrumenter = new SampleInstrumenter(outDirInfo, inputDirInfo); var profile = LanguageSupports.GetCoverageModeByClassName("Java"); var regexes = profile.FilePatterns.Select( pattern => new Regex(pattern.Replace("*", ".*").Replace("?", "."))); outDirInfo.Create(); var fileInfos = inputDirInfo.EnumerateFiles("*", SearchOption.AllDirectories); foreach (var fileInfo in fileInfos) { if (regexes.Any(regex => regex.IsMatch(fileInfo.FullName))) { if (!fileInfo.FullName.StartsWith(excludeInDirInfo.FullName)) { instrumenter.WriteInstrumentedProductionCode(profile, fileInfo); } else { instrumenter.WriteInstrumentedTestCode(profile, fileInfo); } } else { instrumenter.CopyFile(fileInfo); } } profile.CopyLibraries(instrumenter.OutDirInfo, RecordingMode.TextFile); }
public void InsertInstrumentationCode(string fileName) { var profile = LanguageSupports.GetCoverageModeByClassName("Java"); CodeInsertTest.InsertInstrumentationCode(profile, fileName); var info = new CoverageInfo( Fixture.GetCoverageInputPath(), profile.Name, SharingMethod.SharedMemory); var inPath = Path.Combine(Fixture.GetCoverageInputPath(), fileName); var codeFile = new FileInfo(inPath); var relativePath = ParaibaPath.GetRelativePath(codeFile.FullName, info.BasePath); var ast = profile.CodeToXml.GenerateFromFile(codeFile.FullName); File.WriteAllText(Fixture.GetOutputPath(fileName) + ".xml", ast.ToString()); // 測定用コードの埋め込み var path = relativePath; CodeTransformer.InstrumentStatementAndPredicate(info, ast, profile, path); File.WriteAllText(Fixture.GetOutputPath(fileName) + ".modified.xml", ast.ToString()); }
private void BtnStartClick(object sender, EventArgs e) { var files = clbFiles.CheckedItems.Cast <string>(); var basePath = txtBase.Text.AddIfNotEndsWith('\\'); var outDirPath = txtOutput.Text.AddIfNotEndsWith('\\'); var filePathList = files.ToList(); var langName = cmbLanguage.Text; Action action = () => { var profile = LanguageSupports.GetCoverageModeByClassName(langName); var info = new CoverageInfo(basePath, profile.Name, SharingMethod.File); var outDir = new DirectoryInfo(outDirPath); foreach (var filePath in filePathList) { OccfCodeGenerator.WriteCoveragedCode( profile, info, new FileInfo(filePath), outDir); } info.Write(new DirectoryInfo(outDirPath)); }; ProgressForm.Start(this, filePathList.Count, action); }
public void InsertInstrumentationCode(string fileName) { var profile = LanguageSupports.GetCoverageModeByClassName("JavaScript"); CodeInsertTest.InsertInstrumentationCode(profile, fileName); }
public void VerifyInstrumentationCode(string fileName) { var profile = LanguageSupports.GetCoverageModeByClassName("CSharp"); CodeInsertTest.VerifyCodeInsertion(profile, fileName); }
public static bool Run(IList <string> args) { var rootDirPath = ""; var testDirPath = ""; var languageName = "Java"; var libDirPath = ""; var patterns = new List <string>(); var recordingMode = RecordingMode.TextFile; // Set an option grammar var p = new OptionSet { { "r|root=", v => rootDirPath = v }, { "t|test=", v => testDirPath = v }, { "l|lang=", v => languageName = v }, { "i|lib=", v => libDirPath = v }, { "m|mode=", v => { switch (v.ToLower()) { case "text": recordingMode = RecordingMode.TextFile; break; case "binary": recordingMode = RecordingMode.BinaryFile; break; case "shared": recordingMode = RecordingMode.SharedMemory; break; } } }, { "p|pattern=", patterns.Add }, }; // Parse optoins and return arguments excluding parsed options such as "-r root" try { args = p.Parse(args); } catch { Console.WriteLine("Error: can't parse given arguments for the insert command."); return(Program.Print(Usage)); } if (string.IsNullOrEmpty(rootDirPath)) { return(Program.Print(Usage)); } LanguageSupport lang; try { lang = LanguageSupports.GetCoverageModeByClassName(languageName); } catch { return (Program.Print("Error: cant't load script file for programming language of " + languageName)); } var rootDir = new DirectoryInfo(rootDirPath); if (!rootDir.Exists) { return(Program.Print("Root directory doesn't exist.\nroot:" + rootDir.FullName)); } DirectoryInfo testDir = null; if (!string.IsNullOrEmpty(testDirPath)) { testDir = new DirectoryInfo(testDirPath); if (!testDir.Exists) { return (Program.Print("Error: test code directory doesn't exist.\ntest:" + testDir.FullName)); } } var libDir = rootDir; if (!string.IsNullOrEmpty(libDirPath)) { libDir = new DirectoryInfo(libDirPath); if (!libDir.Exists) { return (Program.Print("Error: working directory doesn't exist.\nwork:" + libDir.FullName)); } } if (patterns.Count == 0) { patterns = lang.FilePatterns.ToList(); } if (args.Count == 0) { args = new[] { rootDirPath }; } var fileInfos = GetFileInfos(args, patterns, testDir); InsertMeasurementCode(rootDir, fileInfos, testDir, libDir, lang, recordingMode); return(true); }