Beispiel #1
0
 public static string Serialize(Nitra.Language language, IEnumerable<GrammarDescriptor> dynamicExtensions, LibReference[] libs, Func<string, string> pathConverter)
 {
   var writer = new StringWriter();
   var data = new Language
   {
     Name = language.FullName,
     Path = pathConverter(language.GetType().Assembly.Location),
     DynamicExtensions = dynamicExtensions.Select(g => new DynamicExtension { Name = g.FullName, Path = pathConverter(g.GetType().Assembly.Location) }).ToArray(),
     Libs = libs.Select(x =>  x.Serialize()).ToArray()
   };
   _serializer.Serialize(writer, data);
   return writer.ToString();
 }
Beispiel #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);
    }
        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);
        }
Beispiel #4
0
 public static string MakeXml([NotNull] string root, [NotNull] Language language, [NotNull] IEnumerable<GrammarDescriptor> dynamicExtensions, LibReference[] libs)
 {
   return SerializationHelper.Serialize(language, dynamicExtensions, libs, path => MakeRelativePath(@from: root, isFromDir: true, to: path, isToDir: false));
 }