public TestVm(string testPath, int id, ITestTreeNode parent) : base(parent, testPath) { _testFolder = parent as TestFolderVm; TestPath = testPath; TestSuite = _testFolder == null ? (TestSuiteVm)parent : _testFolder.TestSuite; if (_testFolder != null) { Statistics = null; FileStatistics = new FileStatistics( _testFolder.ParsingStatistics.ReplaceSingleSubtask(Name), _testFolder.ParseTreeStatistics.ReplaceSingleSubtask(Name), _testFolder.AstStatistics.ReplaceSingleSubtask(Name), _testFolder.DependPropsStatistics); _file = new TestFile(this, TestSuite.Language, id, _testFolder.Project, FileStatistics); } else { Statistics = new StatisticsTask.Container("Total"); FileStatistics = new FileStatistics( Statistics.ReplaceSingleSubtask("Parsing"), Statistics.ReplaceSingleSubtask("ParseTree"), Statistics.ReplaceSingleSubtask("Ast", "AST Creation"), Statistics.ReplaceContainerSubtask("DependProps", "Dependent properties")); var solution = new FsSolution <IAst>(); var project = new FsProject <IAst>(solution, Path.GetDirectoryName(testPath), TestSuite.Libs); _file = new TestFile(this, TestSuite.Language, id, project, FileStatistics); } if (TestSuite.TestState == TestState.Ignored) { TestState = TestState.Ignored; } }
//public ObservableCollection<IAst> CompilationUnits { get; private set; } public TestFolderVm(string testPath, TestSuiteVm testSuite) : base(testSuite, testPath) { var solution = new FsSolution<IAst>(); this.Project = new FsProject<IAst>(solution, testPath, testSuite.Libs.Select( lib => { var file = lib as FileLibReference; if (file == null || Path.IsPathRooted(file.Path)) return lib; return new FileLibReference(Path.Combine(@"..", file.Path)); })); Statistics = new StatisticsTask.Container("Total"); ParsingStatistics = Statistics.ReplaceContainerSubtask("Parsing"); ParseTreeStatistics = Statistics.ReplaceContainerSubtask("ParseTree"); AstStatistics = Statistics.ReplaceContainerSubtask("Ast", "AST Creation"); DependPropsStatistics = Statistics.ReplaceContainerSubtask("DependProps", "Dependent properties"); TestPath = testPath; TestSuite = testSuite; if (TestSuite.TestState == TestState.Ignored) TestState = TestState.Ignored; string testSuitePath = base.FullPath; var tests = new ObservableCollection<TestVm>(); var paths = Directory.GetFiles(testSuitePath, "*.test"); foreach (var path in paths.OrderBy(f => f)) tests.Add(new TestVm(path, this)); Tests = tests; }
//public ObservableCollection<IAst> CompilationUnits { get; private set; } public TestFolderVm(string testPath, TestSuiteVm testSuite) : base(testSuite, testPath) { var solution = new FsSolution <IAst>(); this.Project = new FsProject <IAst>(solution, testPath, testSuite.Libs.Select( lib => { var file = lib as FileLibReference; if (file == null || Path.IsPathRooted(file.Path)) { return(lib); } return(new FileLibReference(Path.Combine(@"..", file.Path))); })); Statistics = new StatisticsTask.Container("Total"); ParsingStatistics = Statistics.ReplaceContainerSubtask("Parsing"); ParseTreeStatistics = Statistics.ReplaceContainerSubtask("ParseTree"); AstStatistics = Statistics.ReplaceContainerSubtask("Ast", "AST Creation"); DependPropsStatistics = Statistics.ReplaceContainerSubtask("DependProps", "Dependent properties"); TestPath = testPath; TestSuite = testSuite; if (TestSuite.TestState == TestState.Ignored) { TestState = TestState.Ignored; } string testSuitePath = base.FullPath; var tests = new ObservableCollection <TestVm>(); var paths = Directory.GetFiles(testSuitePath, "*.test"); var id = 0; foreach (var path in paths.OrderBy(f => f)) { tests.Add(new TestVm(path, id, this)); id++; } Tests = tests; }
public TestSuiteVm(SolutionVm solution, string name, string config) : base(solution, Path.Combine(solution.RootFolder, name)) { Statistics = new StatisticsTask.Container("TestSuite", "Test Suite"); string testSuitePath = base.FullPath; var rootPath = solution.RootFolder; Solution = solution; _rootPath = rootPath; TestSuitePath = testSuitePath; Language = Language.Instance; DynamicExtensions = new ObservableCollection <GrammarDescriptor>(); Assemblies = NoAssembiles; var libs = new List <LibReference> { new FileLibReference(Nitra.Visualizer.Utils.NitraRuntimePath) }; var configPath = Path.GetFullPath(Path.Combine(testSuitePath, ConfigFileName)); try { var assemblyRelativePaths = new Dictionary <string, Assembly>(); var languageAndExtensions = SerializationHelper.Deserialize(File.ReadAllText(configPath), path => { var fullPath = Path.GetFullPath(Path.Combine(rootPath, path)); Assembly result; if (!assemblyRelativePaths.TryGetValue(fullPath, out result)) { assemblyRelativePaths.Add(fullPath, result = Utils.LoadAssembly(fullPath, config)); } return(result); }); Language = languageAndExtensions.Item1; foreach (var ext in languageAndExtensions.Item2) { DynamicExtensions.Add(ext); } Assemblies = assemblyRelativePaths.Values.ToArray(); libs.AddRange(languageAndExtensions.Item3); var indent = Environment.NewLine + " "; var para = Environment.NewLine + Environment.NewLine; _hint = "Language:" + indent + Language.FullName + para + "DynamicExtensions:" + indent + string.Join(indent, DynamicExtensions.Select(g => g.FullName)) + para + "Libraries:" + indent + string.Join(indent, assemblyRelativePaths.Keys); } catch (FileNotFoundException ex) { TestState = TestState.Ignored; string additionMsg = null; if (ex.FileName.EndsWith("config.xml", StringComparison.OrdinalIgnoreCase)) { additionMsg = @"The configuration file (config.xml) does not exist in the test suite folder."; } else if (ex.FileName.EndsWith("Nitra.Runtime.dll", StringComparison.OrdinalIgnoreCase)) { additionMsg = @"Try to recompile the parser."; } if (additionMsg != null) { additionMsg = Environment.NewLine + Environment.NewLine + additionMsg; } _hint = "Failed to load test suite:" + Environment.NewLine + ex.Message + additionMsg; } catch (Exception ex) { TestState = TestState.Ignored; _hint = "Failed to load test suite:" + Environment.NewLine + ex.GetType().Name + ":" + ex.Message; } Libs = libs.ToArray(); Name = Path.GetFileName(testSuitePath); var tests = new ObservableCollection <ITest>(); if (Directory.Exists(testSuitePath)) { var paths = Directory.GetFiles(testSuitePath, "*.test").Concat(Directory.GetDirectories(testSuitePath)); var id = 0; foreach (var path in paths.OrderBy(f => f)) { if (Directory.Exists(path)) { tests.Add(new TestFolderVm(path, this)); } else { tests.Add(new TestVm(path, id, this)); } id++; } } else if (TestState != TestState.Ignored) { _hint = "The test suite folder '" + Path.GetDirectoryName(testSuitePath) + "'does not exist."; TestState = TestState.Ignored; } Tests = tests; solution.TestSuites.Add(this); }
public TestSuiteVm(SolutionVm solution, string name, string config) : base(solution, Path.Combine(solution.RootFolder, name)) { Statistics = new StatisticsTask.Container("TestSuite", "Test Suite"); string testSuitePath = base.FullPath; var rootPath = solution.RootFolder; Solution = solution; _rootPath = rootPath; TestSuitePath = testSuitePath; Language = Language.Instance; DynamicExtensions = new ObservableCollection<GrammarDescriptor>(); Assemblies = NoAssembiles; Libs = new LibReference[0]; var configPath = Path.GetFullPath(Path.Combine(testSuitePath, ConfigFileName)); try { var assemblyRelativePaths = new Dictionary<string, Assembly>(); var languageAndExtensions = SerializationHelper.Deserialize(File.ReadAllText(configPath), path => { var fullPath = Path.GetFullPath(Path.Combine(rootPath, path)); Assembly result; if (!assemblyRelativePaths.TryGetValue(fullPath, out result)) assemblyRelativePaths.Add(fullPath, result = Utils.LoadAssembly(fullPath, config)); return result; }); Language = languageAndExtensions.Item1; foreach (var ext in languageAndExtensions.Item2) DynamicExtensions.Add(ext); Assemblies = assemblyRelativePaths.Values.ToArray(); Libs = languageAndExtensions.Item3; var indent = Environment.NewLine + " "; var para = Environment.NewLine + Environment.NewLine; _hint = "Language:" + indent + Language.FullName + para + "DynamicExtensions:" + indent + string.Join(indent, DynamicExtensions.Select(g => g.FullName)) + para + "Libraries:" + indent + string.Join(indent, assemblyRelativePaths.Keys); } catch (FileNotFoundException ex) { TestState = TestState.Ignored; string additionMsg = null; if (ex.FileName.EndsWith("config.xml", StringComparison.OrdinalIgnoreCase)) additionMsg = @"The configuration file (config.xml) does not exist in the test suite folder."; else if (ex.FileName.EndsWith("Nitra.Runtime.dll", StringComparison.OrdinalIgnoreCase)) additionMsg = @"Try to recompile the parser."; if (additionMsg != null) additionMsg = Environment.NewLine + Environment.NewLine + additionMsg; _hint = "Failed to load test suite:" + Environment.NewLine + ex.Message + additionMsg; } catch (Exception ex) { TestState = TestState.Ignored; _hint = "Failed to load test suite:" + Environment.NewLine + ex.GetType().Name + ":" + ex.Message; } Name = Path.GetFileName(testSuitePath); var tests = new ObservableCollection<ITest>(); if (Directory.Exists(testSuitePath)) { var paths = Directory.GetFiles(testSuitePath, "*.test").Concat(Directory.GetDirectories(testSuitePath)); foreach (var path in paths.OrderBy(f => f)) if (Directory.Exists(path)) tests.Add(new TestFolderVm(path, this)); else tests.Add(new TestVm(path, this)); } else if (TestState != TestState.Ignored) { _hint = "The test suite folder '" + Path.GetDirectoryName(testSuitePath) + "'does not exist."; TestState = TestState.Ignored; } Tests = tests; solution.TestSuites.Add(this); }