Пример #1
0
        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);
        }
Пример #2
0
    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);
    }
Пример #3
0
        public TestSuitVm(SolutionVm solution, string name, string config)
            : base(Path.Combine(solution.RootFolder, name))
        {
            string testSuitPath = base.FullPath;
            var    rootPath     = solution.RootFolder;

            Solution      = solution;
            _rootPath     = rootPath;
            TestSuitPath  = testSuitPath;
            SynatxModules = new ObservableCollection <GrammarDescriptor>();

            var gonfigPath = Path.GetFullPath(Path.Combine(testSuitPath, "config.xml"));

            try
            {
                var root = XElement.Load(gonfigPath);
                var libs = root.Elements("Lib").ToList();
                LibPaths = libs.Where(lib => lib.Attribute("Path") != null).Select(lib => lib.Attribute("Path").Value).ToArray();
                var result =
                    libs.Select(lib => Utils.LoadAssembly(Path.GetFullPath(Path.Combine(rootPath, lib.Attribute("Path").Value)), config)
                                .Join(lib.Elements("SyntaxModule"),
                                      m => m.FullName,
                                      m => m.Attribute("Name").Value,
                                      (m, info) => new { Module = m, StartRule = GetStratRule(info.Attribute("StartRule"), m) }));



                foreach (var x in result.SelectMany(lib => lib))
                {
                    SynatxModules.Add(x.Module);
                    if (x.StartRule != null)
                    {
                        Debug.Assert(StartRule == null);
                        StartRule = x.StartRule;
                    }
                }
                var startRuleName = StartRule == null ? "" : StartRule.Name;

                var indent = Environment.NewLine + "  ";
                var para   = Environment.NewLine + Environment.NewLine;

                _hint = "Libraries:" + indent + string.Join(indent, libs.Select(lib => Utils.UpdatePathForConfig(lib.Attribute("Path").Value, config))) + para
                        + "Syntax modules:" + indent + string.Join(indent, SynatxModules.Select(m => m.FullName)) + para
                        + "Start rule:" + indent + startRuleName;
            }
            catch (FileNotFoundException ex)
            {
                TestState = TestState.Ignored;

                string additionMsg = null;

                if (ex.FileName.EndsWith("config.xml", StringComparison.OrdinalIgnoreCase))
                {
                    additionMsg = @"The configuration file (config.xml) not exists in the test suit 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(testSuitPath);

            var tests = new ObservableCollection <TestVm>();

            if (Directory.Exists(testSuitPath))
            {
                foreach (var testPath in Directory.GetFiles(testSuitPath, "*.test").OrderBy(f => f))
                {
                    tests.Add(new TestVm(testPath, this));
                }
            }
            else if (TestState != TestState.Ignored)
            {
                _hint     = "The test suite folder '" + Path.GetDirectoryName(testSuitPath) + "' not exists.";
                TestState = TestState.Ignored;
            }

            Tests = tests;
            solution.TestSuits.Add(this);
        }
Пример #4
0
 private void OpenSolution(string solutionFilePath)
 {
     _settings.CurrentSolution = solutionFilePath;
       _solution = new SolutionVm(solutionFilePath, null, _settings.Config);
       _testsTreeView.ItemsSource = _solution.TestSuits;
       RecentFileList.InsertFile(solutionFilePath);
 }
Пример #5
0
        static void Start(string solutinFilePath, string config)
        {
            var solution = new SolutionVm(solutinFilePath, null, config);
              var testSuits = solution.TestSuits;

              var maxNameLen = CalcMaxNameLen(testSuits);
              var someTestsFailed = false;
              var someTestSuitsFailedToLoad = false;

              foreach (var suit in testSuits)
              {
            PrintLine("Test suit: " + suit.Name);
            Indent();

            if (suit.TestState == TestState.Ignored)
            {
              PrintLine(suit.Hint, ConsoleColor.Red);
              someTestSuitsFailedToLoad = true;
              Unindent();
              continue;
            }

            foreach (var test in suit.Tests)
            {
              var dots = maxNameLen - test.Name.Length;
              Print(test.Name + " " + new string('.', dots) + " ");
              Console.Out.Flush();
              test.Run();

              switch (test.TestState)
              {
            case TestState.Skipped:
              ContinuePrint("skipped.", ConsoleColor.Yellow);
              break;
            case TestState.Failure:
              ContinuePrint("failed!", ConsoleColor.Red);
              someTestsFailed = true;
              Indent();
              Diff(test);
              Unindent();

             break;
            case TestState.Ignored:
              ContinuePrint("ignored.", ConsoleColor.Yellow);
              break;
            case TestState.Inconclusive:
              ContinuePrint("inconclusive.", ConsoleColor.Yellow);
              break;
            case TestState.Success:
              ContinuePrint("passed.", ConsoleColor.Green);
              break;
            default:
              break;
              }
            }

            Unindent();
              }

              if (someTestSuitsFailedToLoad)
            PrintLine("Some test suits is failed to load!", ConsoleColor.Red);
              if (someTestsFailed)
            PrintLine("Some tests is failed!", ConsoleColor.Red);

              Console.WriteLine("done...");

              if (someTestsFailed || someTestSuitsFailedToLoad)
              {
            //Console.ReadLine();
            Environment.Exit(-1);
              }
        }
Пример #6
0
        public MainWindow()
        {
            _settings = Settings.Default;

              ToolTipService.ShowDurationProperty.OverrideMetadata(
            typeof(DependencyObject),
            new FrameworkPropertyMetadata(Int32.MaxValue));

              InitializeComponent();

              this.Top         = _settings.WindowTop;
              this.Left        = _settings.WindowLeft;
              this.Height      = _settings.WindowHeight;
              this.Width       = _settings.WindowLWidth;
              this.WindowState = (WindowState)_settings.WindowState;
              _mainRow.Height  = new GridLength(_settings.TabControlHeight);

              _configComboBox.ItemsSource = new[] {"Debug", "Release"};
              var config = _settings.Config;
              _configComboBox.SelectedItem = config == "Release" ? "Release" : "Debug";

              _tabControl.SelectedIndex = _settings.ActiveTabIndex;
              _foldingStrategy          = new NitraFoldingStrategy();
              _textBox1Tooltip          = new ToolTip { PlacementTarget = _text };
              _parseTimer               = new Timer { AutoReset = false, Enabled = false, Interval = 300 };
              _parseTimer.Elapsed      += _parseTimer_Elapsed;

              _text.TextArea.Caret.PositionChanged += Caret_PositionChanged;

              _highlightingStyles = new Dictionary<string, HighlightingColor>
              {
            { "Keyword",  new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Blue) } },
            { "Comment",  new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Green) } },
            { "Number",   new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Magenta) } },
            { "Operator", new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Navy) } },
            { "String",   new HighlightingColor { Foreground = new SimpleHighlightingBrush(Colors.Maroon) } },
              };

              _foldingManager    = FoldingManager.Install(_text.TextArea);
              _textMarkerService = new TextMarkerService(_text.Document);

              _text.TextArea.TextView.BackgroundRenderers.Add(_textMarkerService);
              _text.TextArea.TextView.LineTransformers.Add(_textMarkerService);
              _text.Options.ConvertTabsToSpaces = true;
              _text.Options.EnableRectangularSelection = true;
              _text.Options.IndentationSize = 2;
              _testsTreeView.SelectedValuePath = "FullPath";

              if (string.IsNullOrWhiteSpace(_settings.CurrentSolution))
            _solution = null;
              else
            LoadTests();
        }
Пример #7
0
        private void LoadTests()
        {
            var selected = _testsTreeView.SelectedItem as FullPathVm;
              var selectedPath     = selected == null ? null : selected.FullPath;

              if (!File.Exists(_settings.CurrentSolution ?? ""))
              {
            MessageBox.Show(this, "Solution '" + _settings.CurrentSolution + "' not exists!");
            return;
              }

              _solution = new SolutionVm(_settings.CurrentSolution, selectedPath, _settings.Config);
              this.Title = _solution.Name + " - " + Constants.AppName;
              _testsTreeView.ItemsSource = _solution.TestSuits;
        }
Пример #8
0
    static void Start(string solutinFilePath, string config)
    {
      var solution = new SolutionVm(solutinFilePath, null, config);
      var testSuites = solution.TestSuites;

      var maxNameLen = CalcMaxNameLen(testSuites);
      var someTestsFailed = false;
      var someTestSuitesFailedToLoad = false;

      foreach (var suite in testSuites)
      {
        PrintLine("Test suite: " + suite.Name);
        Indent();

        if (suite.TestState == TestState.Ignored)
        {
          PrintLine(suite.Hint, ConsoleColor.Red);
          someTestSuitesFailedToLoad = true;
          Unindent();
          continue;
        }

        foreach (var test in suite.Tests)
        {
          var dots = maxNameLen - test.Name.Length;
          Print(test.Name + " " + new string('.', dots) + " ");
          Console.Out.Flush();
          {
            var testFile = test as TestVm;
            if (testFile != null)
              someTestsFailed |= RunTestFile(testFile);
          }
          {
            var testFolder = test as TestFolderVm;
            if (testFolder != null)
              foreach (var testFile in testFolder.Tests)
                someTestsFailed |= RunTestFile(testFile);
          }
        }

        Unindent();
      }

      if (someTestSuitesFailedToLoad)
        PrintLine("Some test suits is failed to load!", ConsoleColor.Red);
      if (someTestsFailed)
        PrintLine("Some tests is failed!", ConsoleColor.Red);

      Console.WriteLine("done...");

      if (someTestsFailed || someTestSuitesFailedToLoad)
      {
        //Console.ReadLine();
        Environment.Exit(-1);
      }
    }
Пример #9
0
    public MainWindow()
    {
      _settings = Settings.Default;
      _highlightingStyles = new Dictionary<string, HighlightingColor>(StringComparer.OrdinalIgnoreCase);

      ToolTipService.ShowDurationProperty.OverrideMetadata(
        typeof(DependencyObject),
        new FrameworkPropertyMetadata(Int32.MaxValue));

      InitializeComponent();

      _mainRow.Height  = new GridLength(_settings.TabControlHeight);


      _configComboBox.ItemsSource = new[] {"Debug", "Release"};
      var config = _settings.Config;
      _configComboBox.SelectedItem = config == "Release" ? "Release" : "Debug";

      _tabControl.SelectedIndex = _settings.ActiveTabIndex;
      _foldingStrategy          = new NitraFoldingStrategy();
      _textBox1Tooltip          = new ToolTip { PlacementTarget = _text };
      _parseTimer               = new Timer { AutoReset = false, Enabled = false, Interval = 300 };
      _parseTimer.Elapsed      += _parseTimer_Elapsed;

      _text.TextArea.Caret.PositionChanged += Caret_PositionChanged;

      _foldingManager    = FoldingManager.Install(_text.TextArea);
      _textMarkerService = new TextMarkerService(_text.Document);

      _text.TextArea.TextView.BackgroundRenderers.Add(_textMarkerService);
      _text.TextArea.TextView.LineTransformers.Add(_textMarkerService);
      _text.Options.ConvertTabsToSpaces = true;
      _text.Options.EnableRectangularSelection = true;
      _text.Options.IndentationSize = 2;
      _testsTreeView.SelectedValuePath = "FullPath";
      _propertyGrid = new PependentPropertyGrid();
      _windowsFormsHost.Child = _propertyGrid;

      if (string.IsNullOrWhiteSpace(_settings.CurrentSolution))
        _solution = null;
      else
        LoadTests();
    }
Пример #10
0
        public TestSuitVm(SolutionVm solution, string name, string config)
            : base(Path.Combine(solution.RootFolder, name))
        {
            string testSuitPath = base.FullPath;
              var rootPath = solution.RootFolder;
              Solution = solution;
              _rootPath = rootPath;
              TestSuitPath = testSuitPath;
              SynatxModules = new ObservableCollection<GrammarDescriptor>();

              var gonfigPath = Path.GetFullPath(Path.Combine(testSuitPath, "config.xml"));

              try
              {
            var root = XElement.Load(gonfigPath);
            var libs = root.Elements("Lib").ToList();
            LibPaths = libs.Where(lib => lib.Attribute("Path") != null).Select(lib => lib.Attribute("Path").Value).ToArray();
            var result =
              libs.Select(lib => Utils.LoadAssembly(Path.GetFullPath(Path.Combine(rootPath, lib.Attribute("Path").Value)), config)
            .Join(lib.Elements("SyntaxModule"),
              m => m.FullName,
              m => m.Attribute("Name").Value,
              (m, info) => new { Module = m, StartRule = GetStratRule(info.Attribute("StartRule"), m) }));

            foreach (var x in result.SelectMany(lib => lib))
            {
              SynatxModules.Add(x.Module);
              if (x.StartRule != null)
              {
            Debug.Assert(StartRule == null);
            StartRule = x.StartRule;
              }
            }
            var startRuleName = StartRule == null ? "" : StartRule.Name;

            var indent = Environment.NewLine + "  ";
            var para = Environment.NewLine + Environment.NewLine;

            _hint = "Libraries:" + indent + string.Join(indent, libs.Select(lib => Utils.UpdatePathForConfig(lib.Attribute("Path").Value, config))) + para
               + "Syntax modules:" + indent + string.Join(indent, SynatxModules.Select(m => m.FullName)) + para
               + "Start rule:" + indent + startRuleName;
              }
              catch (FileNotFoundException ex)
              {
            TestState = TestState.Ignored;

            string additionMsg = null;

            if (ex.FileName.EndsWith("config.xml", StringComparison.OrdinalIgnoreCase))
              additionMsg = @"The configuration file (config.xml) not exists in the test suit 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(testSuitPath);

              var tests = new ObservableCollection<TestVm>();

              if (Directory.Exists(testSuitPath))
            foreach (var testPath in Directory.GetFiles(testSuitPath, "*.test").OrderBy(f => f))
              tests.Add(new TestVm(testPath, this));
              else if (TestState != TestState.Ignored)
              {
            _hint = "The test suite folder '" + Path.GetDirectoryName(testSuitPath) + "' not exists.";
            TestState = TestState.Ignored;
              }

              Tests = tests;
              solution.TestSuits.Add(this);
        }