Пример #1
0
 public void AddCircularRoot()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\Circular"))
     {
         File.Delete(Path.Combine(temp.DirPath, "foo.rs"));
         File.Create(Path.Combine(temp.DirPath, "foo.rs")).Close();
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "main.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(0, reached.Count);
         File.Delete(Path.Combine(temp.DirPath, "foo.rs"));
         using (var stream = File.Open(Path.Combine(temp.DirPath, "foo.rs"), FileMode.CreateNew))
         {
             using (var textStream = new StreamWriter(stream))
             {
                 textStream.Write("mod bar;");
             }
         }
         var diff = tracker.Reparse(Path.Combine(temp.DirPath, "foo.rs"));
         // Return check
         Assert.AreEqual(2, diff.Added.Count);
         Assert.AreEqual(0, diff.Removed.Count);
         // Model check
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"), Path.Combine(temp.DirPath, "foo.rs"));
     }
 }
Пример #2
0
        private static void ModelCheck(ModuleTracker t, string root, params string[] additionalRoots)
        {
#if TEST // Dirty hack
            ModuleTracker model = new ModuleTracker(root);
            foreach (string r in additionalRoots)
                model.AddRootModule(r);
            model.ExtractReachableAndMakeIncremental();
            Assert.True(t.IsEquivalnet(model));
#endif
        }
Пример #3
0
        private static void ModelCheck(ModuleTracker t, string root, params string[] additionalRoots)
        {
#if TEST // Dirty hack
            ModuleTracker model = new ModuleTracker(root);
            foreach (string r in additionalRoots)
            {
                model.AddRootModule(r);
            }
            model.ExtractReachableAndMakeIncremental();
            Assert.True(t.IsEquivalnet(model));
#endif
        }
Пример #4
0
 public void NonIncrRootRemoval()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\CircularMultiRoot"))
     {
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "lib.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(1, reached.Count);
         HashSet <string> orphans = tracker.DowngradeModule(Path.Combine(temp.DirPath, "foo.rs")).Orphans;
         Assert.AreEqual(2, orphans.Count);
         ModelCheck(tracker, Path.Combine(temp.DirPath, "lib.rs"));
     }
 }
Пример #5
0
 public void ClearCircularRoot()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\Circular"))
     {
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "main.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(2, reached.Count);
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "baz.rs"));
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "bar.rs"));
         File.Delete(Path.Combine(temp.DirPath, "foo.rs"));
         File.Create(Path.Combine(temp.DirPath, "foo.rs")).Close();
         var diff = tracker.Reparse(Path.Combine(temp.DirPath, "foo.rs"));
         // Return check
         Assert.AreEqual(0, diff.Added.Count);
         Assert.AreEqual(2, diff.Removed.Count);
         // Model check
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"), Path.Combine(temp.DirPath, "foo.rs"));
     }
 }
Пример #6
0
 public void UpgradeAndDowngrade()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\CircularConnected"))
     {
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "main.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(2, reached.Count);
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "baz.rs"));
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "bar.rs"));
         var res = tracker.DowngradeModule(Path.Combine(temp.DirPath, "foo.rs"));
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"));
         tracker.UpgradeModule(Path.Combine(temp.DirPath, "baz.rs"));
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"), Path.Combine(temp.DirPath, "baz.rs"));
         res = tracker.DowngradeModule(Path.Combine(temp.DirPath, "baz.rs"));
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"));
         Assert.AreEqual(0, res.Orphans.Count);
         Assert.True(res.IsReferenced);
     }
 }
Пример #7
0
 public void AddCircularRoot()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\Circular"))
     {
         File.Delete(Path.Combine(temp.DirPath, "foo.rs"));
         File.Create(Path.Combine(temp.DirPath, "foo.rs")).Close();
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "main.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(0, reached.Count);
         File.Delete(Path.Combine(temp.DirPath, "foo.rs"));
         using (var stream = File.Open(Path.Combine(temp.DirPath, "foo.rs"), FileMode.CreateNew))
         {
             using (var textStream = new StreamWriter(stream))
             {
                 textStream.Write("mod bar;");
             }
         }
         var diff = tracker.Reparse(Path.Combine(temp.DirPath, "foo.rs"));
         // Return check
         Assert.AreEqual(2, diff.Added.Count);
         Assert.AreEqual(0, diff.Removed.Count);
         // Model check
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"), Path.Combine(temp.DirPath, "foo.rs"));
     }
 }
Пример #8
0
 public void ClearCircularRoot()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\Circular"))
     {
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "main.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(2, reached.Count);
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "baz.rs"));
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "bar.rs"));
         File.Delete(Path.Combine(temp.DirPath, "foo.rs"));
         File.Create(Path.Combine(temp.DirPath, "foo.rs")).Close();
         var diff = tracker.Reparse(Path.Combine(temp.DirPath, "foo.rs"));
         // Return check
         Assert.AreEqual(0, diff.Added.Count);
         Assert.AreEqual(2, diff.Removed.Count);
         // Model check
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"), Path.Combine(temp.DirPath, "foo.rs"));
     }
 }
Пример #9
0
 public void UpgradeAndDowngrade()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\CircularConnected"))
     {
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "main.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(2, reached.Count);
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "baz.rs"));
         CollectionAssert.Contains(reached, Path.Combine(temp.DirPath, "bar.rs"));
         var res = tracker.DowngradeModule(Path.Combine(temp.DirPath, "foo.rs"));
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"));
         tracker.UpgradeModule(Path.Combine(temp.DirPath, "baz.rs"));
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"), Path.Combine(temp.DirPath, "baz.rs"));
         res = tracker.DowngradeModule(Path.Combine(temp.DirPath, "baz.rs"));
         ModelCheck(tracker, Path.Combine(temp.DirPath, "main.rs"));
         Assert.AreEqual(0, res.Orphans.Count);
         Assert.True(res.IsReferenced);
     }
 }
Пример #10
0
 public void NonIncrRootRemoval()
 {
     using (TemporaryDirectory temp = Utils.LoadResourceDirectory(@"Internal\CircularMultiRoot"))
     {
         var tracker = new ModuleTracker(Path.Combine(temp.DirPath, "lib.rs"));
         tracker.AddRootModule(Path.Combine(temp.DirPath, "foo.rs"));
         var reached = tracker.ExtractReachableAndMakeIncremental();
         Assert.AreEqual(1, reached.Count);
         HashSet<string> orphans = tracker.DowngradeModule(Path.Combine(temp.DirPath, "foo.rs")).Orphans;
         Assert.AreEqual(2, orphans.Count);
         ModelCheck(tracker, Path.Combine(temp.DirPath, "lib.rs"));
     }
 }