public static void RunTest(CSharpFile file)
		{
			int seed;
			lock (sharedRnd) {
				seed = sharedRnd.Next();
			}
			Random rnd = new Random(seed);
			var test = new RandomizedOrderResolverTest();
			// Resolve all nodes, but in a random order without using a navigator.
			test.resolver = new CSharpAstResolver(file.Project.Compilation, file.CompilationUnit, file.ParsedFile);
			// For comparing whether the results are equivalent, we also use a normal 'resolve all' resolver:
			test.resolveAllResolver = new CSharpAstResolver(file.Project.Compilation, file.CompilationUnit, file.ParsedFile);
			test.resolveAllResolver.ApplyNavigator(new ResolveAllNavigator(), CancellationToken.None);
			// Prepare list of actions that we need to verify:
			var actions = new List<Func<bool>>();
			bool checkResults = rnd.Next(0, 2) == 0;
			bool checkStateBefore = rnd.Next(0, 2) == 0;
			bool checkStateAfter = rnd.Next(0, 2) == 0;
			bool checkConversion = rnd.Next(0, 2) == 0;
			bool checkExpectedType = rnd.Next(0, 2) == 0;
			foreach (var _node in file.CompilationUnit.DescendantsAndSelf) {
				var node = _node;
				if (CSharpAstResolver.IsUnresolvableNode(node))
					continue;
				if (checkResults)
					actions.Add(() => test.CheckResult(node));
				if (checkStateBefore)
					actions.Add(() => test.CheckStateBefore(node));
				if (checkStateAfter)
					actions.Add(() => test.CheckStateAfter(node));
				var expr = node as Expression;
				if (expr != null) {
					if (checkConversion)
						actions.Add(() => test.CheckConversion(expr));
					if (checkExpectedType)
						actions.Add(() => test.CheckExpectedType(expr));
				}
			}
			
			// Fisher-Yates shuffle
			for (int i = actions.Count - 1; i > 0; i--) {
				int j = rnd.Next(0, i);
				var tmp = actions[i];
				actions[i] = actions[j];
				actions[j] = tmp;
			}
			
			foreach (var action in actions) {
				if (!action()) {
					Console.WriteLine("Seed for this file was: " + seed);
					break;
				}
			}
		}
Пример #2
0
        public static void RunTestWithoutUnresolvedFile(CSharpFile file)
        {
            CSharpAstResolver resolver = new CSharpAstResolver(file.Project.Compilation, file.SyntaxTree);
            var navigator = new ValidatingResolveAllNavigator(file.FileName);

            resolver.ApplyNavigator(navigator, CancellationToken.None);
            navigator.Validate(resolver, file.SyntaxTree);

            CSharpAstResolver originalResolver = new CSharpAstResolver(file.Project.Compilation, file.SyntaxTree, file.UnresolvedTypeSystemForFile);

            foreach (var node in file.SyntaxTree.DescendantsAndSelf)
            {
                var originalResult = originalResolver.Resolve(node);
                var result         = resolver.Resolve(node);
                if (!RandomizedOrderResolverTest.IsEqualResolveResult(result, originalResult))
                {
                    Console.WriteLine("Got different without IUnresolvedFile at " + file.FileName + ":" + node.StartLocation);
                }
            }
        }
        public static void RunTest(CSharpFile file)
        {
            int seed;

            lock (sharedRnd) {
                seed = sharedRnd.Next();
            }
            Random rnd  = new Random(seed);
            var    test = new RandomizedOrderResolverTest();

            // Resolve all nodes, but in a random order without using a navigator.
            test.resolver = new CSharpAstResolver(file.Project.Compilation, file.SyntaxTree, file.UnresolvedTypeSystemForFile);
            // For comparing whether the results are equivalent, we also use a normal 'resolve all' resolver:
            test.resolveAllResolver = new CSharpAstResolver(file.Project.Compilation, file.SyntaxTree, file.UnresolvedTypeSystemForFile);
            test.resolveAllResolver.ApplyNavigator(new ResolveAllNavigator(), CancellationToken.None);
            // Prepare list of actions that we need to verify:
            var  actions           = new List <Func <bool> >();
            bool checkResults      = rnd.Next(0, 2) == 0;
            bool checkStateBefore  = rnd.Next(0, 2) == 0;
            bool checkStateAfter   = rnd.Next(0, 2) == 0;
            bool checkConversion   = rnd.Next(0, 2) == 0;
            bool checkExpectedType = rnd.Next(0, 2) == 0;

            foreach (var _node in file.SyntaxTree.DescendantsAndSelf)
            {
                var node = _node;
                if (CSharpAstResolver.IsUnresolvableNode(node))
                {
                    continue;
                }
                if (checkResults)
                {
                    actions.Add(() => test.CheckResult(node));
                }
                if (checkStateBefore)
                {
                    actions.Add(() => test.CheckStateBefore(node));
                }
                if (checkStateAfter)
                {
                    actions.Add(() => test.CheckStateAfter(node));
                }
                var expr = node as Expression;
                if (expr != null)
                {
                    if (checkConversion)
                    {
                        actions.Add(() => test.CheckConversion(expr));
                    }
                    if (checkExpectedType)
                    {
                        actions.Add(() => test.CheckExpectedType(expr));
                    }
                }
            }

            // Fisher-Yates shuffle
            for (int i = actions.Count - 1; i > 0; i--)
            {
                int j   = rnd.Next(0, i);
                var tmp = actions[i];
                actions[i] = actions[j];
                actions[j] = tmp;
            }

            foreach (var action in actions)
            {
                if (!action())
                {
                    Console.WriteLine("Seed for this file was: " + seed);
                    break;
                }
            }
        }