1 module ut.issues;
2 
3 
4 import ut;
5 import automem;
6 
7 
8 private typeof(vector(1).range()) gVectorIntRange;
9 
10 version(AutomemAsan) {}
11 else {
12 
13     @ShouldFail("https://issues.dlang.org/show_bug.cgi?id=19752")
14     @("26")
15     @safe unittest {
16         static void escape() {
17             auto vec = vector(1, 2, 3);
18             gVectorIntRange = vec.range;
19         }
20 
21         static void stackSmash() {
22             long[4096] arr = 42;
23         }
24 
25         escape;
26         gVectorIntRange.length.should == 0;
27         stackSmash;
28         gVectorIntRange.length.should == 0;
29     }
30 }
31 
32 
33 @("27")
34 @safe unittest {
35     const str = String("foobar");
36 
37     (str == "foobar").should == true;
38     (str == "barfoo").should == false;
39     (str == "quux").should == false;
40 
41     (str == String("foobar")).should == true;
42     (str == String("barfoo")).should == false;
43     (str == String("quux")).should == false;
44 }
45 
46 
47 @("37")
48 @safe unittest {
49 
50     static struct S {
51         int front;
52         void popFront() { ++front; }
53         @property bool empty() { return front >= 10; }
54     }
55 
56     auto rc = RefCounted!S(0);
57     foreach(i; *rc) {}
58 
59     auto un = Unique!S(0);
60     foreach(i; *un) {}
61 }
62 
63 
64 @("38")
65 @safe unittest {
66 
67     import core.exception: AssertError;
68 
69     static struct S {
70         int front = 0;
71     }
72 
73     auto rc = RefCounted!S();
74     rc.front.shouldThrow!AssertError;
75 }
76 
77 
78 version(unitThreadedLight) {}
79 else {
80     @HiddenTest
81     @("51")
82     @system unittest {
83 
84         import std.experimental.allocator: allocatorObject;
85         import std.experimental.allocator.mallocator: Mallocator;
86 
87         static interface Interface {
88             void hello();
89             string test();
90         }
91 
92         static class Oops: Interface {
93             private ubyte[] _buffer;
94             override void hello() {}
95             override string test() { return "foo"; }
96             this() { _buffer.length = 1024 * 1024; }
97             ~this() {}
98 
99             static Oops opCall() {
100                 import std.experimental.allocator: theAllocator, make;
101                 return theAllocator.make!Oops;
102             }
103         }
104 
105         Vector!Interface interfaces;
106         foreach(i; 0 .. 12) interfaces ~= Oops();
107     }
108 }
109 
110 
111 int created, destroyed;
112 
113 struct Issue156 {
114 
115     @disable this();
116     @disable this(this);
117 
118     this(int val) {
119         writelnUt(" Issue156(", val, ")");
120         this.val = val;
121         created++;
122     }
123     ~this() {
124         writelnUt("~Issue156(", val, ")");
125         destroyed++;
126     }
127     int val;
128 }
129 
130 
131 version(AutomemAsan) {}
132 else {
133     @("56")
134     @ShouldFail
135     @system unittest {
136 
137         import std.range;
138 
139         {
140             RefCounted!Issue156 s = RefCounted!Issue156(1);
141             writelnUt("Creating r1");
142             auto r1 = repeat(s, 2);
143             writelnUt("Creating r2");
144             auto r2 = repeat(s, 2);
145             writelnUt("iterating");
146             foreach(s1, s2; lockstep(r1, r2))
147                 s1.val.should == s2.val;
148         }
149         writelnUt("after lockstep: created ", created, " vs destroyed ", destroyed);
150         created.should == 1;
151         destroyed.should == 1;
152         {
153             RefCounted!Issue156 s = RefCounted!Issue156(2);
154             writelnUt("Creating r1");
155             auto r1 = repeat(s, 2);
156             writelnUt("Creating r2");
157             auto r2 = repeat(s, 2);
158             writelnUt("iterating");
159             foreach(s1, s2; zip(r1, r2))
160                 s1.val.should == s2.val;
161         }
162         writelnUt("after zip: created ", created, " vs destroyed ", destroyed);
163         created.should == 2;
164         destroyed.should == 2;
165     }
166 }