Beispiel #1
0
 public override TestResult Merge(TestResult other)
 {
     if (other is Success success)
     {
         return(new Success(Succeeded.Concat(success.Succeeded)));
     }
     else if (other is Failure failure)
     {
         return(new Failure(Succeeded.Concat(failure.Succeeded), failure.Failed));
     }
     throw Release.Fail("This location is thought to be unreachable");
 }
 public SourceSymbolContext(
     IMethod?scope,
     IAssembly assembly,
     ImmutableArray <QualifiedName> imports,
     QualifiedName?nameSpace,
     Func <ImmutableArray <ITypeParameter> > currentLevelTypeParameters)
 {
     Scope     = scope;
     Assembly  = assembly;
     Imports   = imports.IsDefault ? throw Release.Fail("imports cannot be default") : imports;
     NameSpace = nameSpace;
     CurrentLevelTypeParameters = currentLevelTypeParameters;
 }
Beispiel #3
0
        public static TestResult RunTests(Assembly compiledAssembly)
        {
            var methods =
                compiledAssembly
                .ExportedTypes
                .SelectMany(x => x.GetMethods(BindingFlags.Static | BindingFlags.Public))
                .Where(x =>
                       x.GetParameters().Length == 0 &&
                       (x.ReturnType == typeof(string) || x.ReturnType == typeof(bool)));

            var successes = new List <string>();
            var failures  = new List <(string name, string message)>();

            foreach (var method in methods)
            {
                object?result;
                try
                {
                    result = method.Invoke(null, null);
                }
                catch (Exception e)
                {
                    result = e.ToString();
                }

                switch (result)
                {
                case true:
                case "":
                case null:
                    successes.Add(method.Name);
                    break;

                case false:
                    failures.Add((method.Name, "failed"));
                    break;

                case string message:
                    failures.Add((method.Name, message));
                    break;

                default:
                    Release.Fail("This location is thought to be unreachable");
                    break;
                }
            }

            return(failures.Any()
                                ? (TestResult) new TestResult.Failure(successes, failures)
                                : new TestResult.Success(successes));
        }
 public MethodOrInterfaceMethod SubstituteTypeParameters(ImmutableArrayDictionary <ITypeParameter, IType> substitutions, Dictionary <IType, IType> substituted)
 {
     if (_method != null)
     {
         var typeArguments = _typeArguments.Select(x => substitutions.TryGetValue(x, out var tp) ? tp as ITypeParameter : x).ToImmutableArray();
         if (typeArguments.Any(x => x is null))
         {
             typeArguments = ImmutableArray <ITypeParameter> .Empty !;
         }
         return(new MethodOrInterfaceMethod(_method.Substitute(substitutions, substituted), typeArguments !));
     }
     if (_interfaceMethod != null)
     {
         return(new MethodOrInterfaceMethod(_interfaceMethod.Substitute(substitutions, substituted)));
     }
     throw Release.Fail("Do not use default constructor for " + nameof(MethodOrInterfaceMethod));
 }