Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github60486.cs « regressions « DefaultInterfaceMethods « classloader « Loader « tests « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fa751c14ee8146e08f6e3d4cea4923d8e8cdd630 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Runtime.CompilerServices;

public interface IPublisher<out TData>
{
    event Action<TData> OnPublish;
}

public interface TestItf1<TT>
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestMethod1(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        StackFrame.Validate(Environment.StackTrace, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestMethod2(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod3(this, publisher, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    protected static void TestMethod3(TestItf1<TT> subscriber, IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        StackFrame.Validate(Environment.StackTrace, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestMethod4(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod3(this, publisher, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestMethod5(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod3(this, publisher, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestMethod10(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod3(this, publisher, expectedFrames);
    }

    void TestMethod11(IPublisher<TT> publisher, StackFrame[] expectedFrames);
}

public interface TestItf2<TT> : TestItf1<TT>
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestItf1<TT>.TestMethod5(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod3(this, publisher, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestItf1<TT>.TestMethod10(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod3(this, publisher, expectedFrames);
    }
}

public interface TestItf3<TT> : TestItf1<TT>
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestMethod6(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod3(this, publisher, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestMethod7(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod8(this, publisher, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    protected static void TestMethod8(TestItf1<TT> subscriber, IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        StackFrame.Validate(Environment.StackTrace, expectedFrames);
    }

    void TestMethod9(IPublisher<TT> publisher, StackFrame[] expectedFrames);
}

public interface TestItf4<TT> : TestItf3<TT>
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    void TestItf3<TT>.TestMethod9(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestMethod8(this, publisher, expectedFrames);
    }
}

public class ProgramBase<TT> : TestItf4<TT>
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public void TestMethod10(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestItf1<TT>.TestMethod3(this, publisher, expectedFrames);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public void TestMethod11(IPublisher<TT> publisher, StackFrame[] expectedFrames)
    {
        TestItf1<TT>.TestMethod3(this, publisher, expectedFrames);
    }
}

public class Program : ProgramBase<InputData>, TestItf2<InputData>
{
    static int Main(string[] args)
    {
        new Program().Start();
        return 100;
    }

    public void Start()
    {
        var t1 = this as TestItf1<InputData>;
        t1.TestMethod1(null, new[] { new StackFrame("TestItf1`1", "TestMethod1") });
        t1.TestMethod2(null, new[] { new StackFrame("TestItf1`1", "TestMethod3"), new StackFrame("TestItf1`1", "TestMethod2") });
        t1.TestMethod4(null, new[] { new StackFrame("TestItf1`1", "TestMethod3"), new StackFrame("Program", "TestMethod4") });
        t1.TestMethod5(null, new[] { new StackFrame("TestItf1`1", "TestMethod3"), new StackFrame(new[] { "TestItf2`1", "TestItf1" }, "TestMethod5") });

        var t3 = this as TestItf3<InputData>;
        t3.TestMethod6(null, new[] { new StackFrame("TestItf1`1", "TestMethod3"), new StackFrame("TestItf3`1", "TestMethod6") });
        t3.TestMethod7(null, new[] { new StackFrame("TestItf3`1", "TestMethod8"), new StackFrame("TestItf3`1", "TestMethod7") });
        t3.TestMethod9(null, new[] { new StackFrame("TestItf3`1", "TestMethod8"), new StackFrame(new[] { "TestItf4`1", "TestItf3" }, "TestMethod9") });

        t1.TestMethod10(null, new[] { new StackFrame("TestItf1`1", "TestMethod3"), new StackFrame("ProgramBase`1", "TestMethod10") });
        t1.TestMethod11(null, new[] { new StackFrame("TestItf1`1", "TestMethod3"), new StackFrame("ProgramBase`1", "TestMethod11") });
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public void TestMethod4(IPublisher<InputData> publisher, StackFrame[] expectedFrames)
    {
        TestItf1<InputData>.TestMethod3(this, publisher, expectedFrames);
    }
}

public class InputData
{
    public int i;
}

public class StackFrame
{
    public string [] ClassName { get; set; }
    public string MethodName { get; set; } = string.Empty;

    public StackFrame(string [] className, string methodName)
    {
        ClassName = className;
        MethodName = methodName;
    }

    public StackFrame(string className, string methodName)
    {
        ClassName = new string[] { className };
        MethodName = methodName;
    }

    public static void Validate(string testStack, StackFrame[] expectedFrames)
    {
        int index = 1;

        string[] lines = testStack.Split(
            new string[] { Environment.NewLine },
            StringSplitOptions.None
        );

        //Console.WriteLine(testStack);

        foreach (var frame in expectedFrames)
        {
            var line = lines[index++].Trim();


            if (!line.StartsWith($"at {frame.ClassName[0]}") || !line.Contains($".{frame.MethodName}") || (frame.ClassName.Length > 1 && !line.Contains($".{frame.ClassName[1]}")))
            {
                Console.WriteLine($"Expected {frame.ClassName}.{frame.MethodName} but got {line}");
                Console.WriteLine(testStack);
                Environment.Exit(1);
            }
        }
    }
}