<div dir="ltr">Thanks Brian!<div><br></div><div>You pointed me in the right direction.  I&#39;ve got a working version up here:</div><div><a href="https://gist.github.com/lzell/3a4f43d00657a347363343c035e5db4c">https://gist.github.com/lzell/3a4f43d00657a347363343c035e5db4c</a><br></div><div><br></div><div>Non-pretty version:</div><div><br></div><div>







<p class="">// Start repl with:<br>
// $ xcrun swift -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks<br>
<br>
// Or run as script:<br>
// $ xcrun swift -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks %<br>
<br>
<br>
import Foundation<br>
<br>
if dlopen(&quot;/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework/Versions/A/XCTest&quot;, RTLD_NOW) == nil {<br>
<span class="">  </span>perror(dlerror())<br>
}<br>
if dlopen(&quot;/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftXCTest.dylib&quot;, RTLD_NOW) == nil {<br>
<span class="">  </span>perror(dlerror())<br>
}<br>
<br>
import XCTest<br>
<br>
class ATest : XCTestCase {<br>
<span class="">    </span>func testIt() {<br>
<span class="">        </span>XCTAssertTrue(false, &quot;Now I see this!&quot;)<br>
<span class="">    </span>}<br>
    func testThat() {<br>
<span class="">        </span>XCTAssertNil(nil, &quot;Passes!&quot;)<br>
<span class="">    </span>}<br>
}<br>
<br>
class BTest : XCTestCase {<br>
<span class="">  </span>func testIt() {<br>
<span class="">    </span>XCTAssertFalse(false, &quot;whatever&quot;)<br>
<span class="">  </span>}<br>
  func testThat() {<br>
<span class="">    </span>XCTAssertEqual(1, 0, &quot;I fail too&quot;)<br>
<span class="">  </span>}<br>
}<br>
<br>
// MARK: -<br>
func selectors&lt;T: XCTestCase&gt;(forType type: T.Type) -&gt; [Selector] {<br>
<span class="">  </span>var selectors = [Selector]()<br>
  var count : UInt32 = 0<br>
  let methods = class_copyMethodList(type, &amp;count)!<br>
  for i in 0..&lt;count {<br>
<span class="">    </span>let method = methods.advanced(by: Int(i)).pointee!<br>
    selectors.append(method_getName(method)!)<br>
<span class="">  </span>}<br>
  return selectors<br>
}<br>
<br>
func runTests(_ types: XCTestCase.Type...) {<br>
<span class="">  </span>let suite = XCTestSuite(name: &quot;Required&quot;)<br>
  for t in types {<br>
<span class="">    </span>let tests = selectors(forType: t).filter() { String($0).hasPrefix(&quot;test&quot;) }<br>
    tests.map(t.init)<br>
<span class="">         </span>.forEach(suite.addTest)<br>
<span class="">  </span>}<br>
  suite.run()<br>
}<br>
<br>
runTests(ATest.self, BTest.self)<br>
</p></div><div><br></div><div><br></div><div>Lou</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 8, 2016 at 10:05 PM, Brian Gesiak <span dir="ltr">&lt;<a href="mailto:modocache@gmail.com" target="_blank">modocache@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><p style="margin:0px 0px 1.2em!important">Lou,</p>
<p style="margin:0px 0px 1.2em!important">Wow, this is awesome!! Excellent work.</p>
<p style="margin:0px 0px 1.2em!important">I have a few ideas as to why you’re not actually seeing any tests run:</p>
<ol style="margin:1.2em 0px;padding-left:2em">
<li style="margin:0.5em 0px">swift-corelibs-xctest expects users to <a href="https://github.com/apple/swift-corelibs-xctest/blob/96144ded862f402a742345b38f8324cf108f0398/Sources/XCTest/Public/XCTestMain.swift#L52" target="_blank">run tests via the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">XCTMain()</code> function</a>. I’m not sure it’s appropriate for your use case, since the function calls <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">exit()</code> directly (and thus has a return type of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">Never</code>). If it does fits your use case, I’d suggest using it, since all of swift-corelibs-xctest’s regression tests assume this function is called.</li>
<li style="margin:0.5em 0px">swift-corelibs-xctest lacks the runtime reflection used by Apple XCTest, and so <a href="https://github.com/apple/swift-corelibs-xctest/blob/1f00ab2c677d9c226dea8fa3f541999d6f4405b6/Sources/XCTest/Private/XCTestCaseSuite.swift#L31" target="_blank">requires users to list their test methods</a>. I think you may see the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">testIt()</code> output by adding the following:</li>
</ol>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)">class MyTest : XCTestCase { 
<span style="background:rgb(221,255,221)">+    static var allTests = {</span>
<span style="background:rgb(221,255,221)">+        return [</span>
<span style="background:rgb(221,255,221)">+            (&quot;testIt&quot;, testIt),</span>
<span style="background:rgb(221,255,221)">+        ]</span>
<span style="background:rgb(221,255,221)">+    }()</span>
    override func setUp() {
</code></pre>
<p style="margin:0px 0px 1.2em!important">Let me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XN0IHRo
ZWlyIHRlc3QgbWV0aG9kc10oaHR0cHM6Ly9naXRodWIuY29tL2FwcGxlL3N3aWZ0LWNvcmVsaWJz
LXhjdGVzdC9ibG9iLzFmMDBhYjJjNjc3ZDljMjI2ZGVhOGZhM2Y1NDE5OTlkNmY0NDA1YjYvU291
cmNlcy9YQ1Rlc3QvUHJpdmF0ZS9YQ1Rlc3RDYXNlU3VpdGUuc3dpZnQjTDMxKS4gSSB0aGluayB5
b3UgbWF5IHNlZSB0aGUgYHRlc3RJdCgpYCBvdXRwdXQgYnkgYWRkaW5nIHRoZSBmb2xsb3dpbmc6
PGJyPjxicj5gYGBkaWZmPGJyPjxkaXY+Y2xhc3MgTXlUZXN0IDogWENUZXN0Q2FzZSB7Jm5ic3A7
PC9kaXY+PGRpdj4rICZuYnNwOyAmbmJzcDtzdGF0aWMgdmFyIGFsbFRlc3RzID0gezwvZGl2Pjxk
aXY+KyAmbmJzcDsgJm5ic3A7ICZuYnNwOyAmbmJzcDtyZXR1cm4gWzwvZGl2PjxkaXY+KyAmbmJz
cDsgJm5ic3A7ICZuYnNwOyAmbmJzcDsgJm5ic3A7ICZuYnNwOygidGVzdEl0IiwgdGVzdEl0KSw8
L2Rpdj48ZGl2PisgJm5ic3A7ICZuYnNwOyAmbmJzcDsgJm5ic3A7XTwvZGl2PjxkaXY+KyAmbmJz
cDsgJm5ic3A7fSgpPC9kaXY+PGRpdj4mbmJzcDsmbmJzcDsgJm5ic3A7b3ZlcnJpZGUgZnVuYyBz
ZXRVcCgpIHs8L2Rpdj5gYGA8ZGl2Pjxicj48L2Rpdj48ZGl2PkxldCBtZSBrbm93IGlmIHRoYXQg
d29ya3MhPGJyPjxicj4tIEJyaWFuIEdlc2lhazxicj48ZGl2Pjxicj48L2Rpdj48L2Rpdj4=" style="min-height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Aug 8, 2016 at 3:25 PM, Lou Zell via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Greetings,<div><br></div><div>I am close to getting XCTests running in the swift repl, but for some reason my tests are never invoked.  Does anyone have a suggestion or see something wrong with the test setup?</div><div><br></div><div>$ xcrun swift -F /Applications/Xcode-beta.app/C<wbr>ontents/Developer/Platforms/Ma<wbr>cOSX.platform/Developer/Librar<wbr>y/Frameworks</div>







<div><pre style="font-family:Consolas,&quot;DejaVu Sans Mono&quot;,&quot;Bitstream Vera Sans Mono&quot;,monospace;font-size:13px;letter-spacing:0.015em;line-height:15.6px;padding:0.5em;border:1px solid rgb(204,204,204);border-radius:2px;background:rgb(240,240,240)"><span style="color:rgb(0,112,32);font-weight:bold">import</span><font color="#000000"> </font><span style="color:rgb(14,132,181);font-weight:bold">Foundation</span><font color="#000000"> 
</font><span style="color:rgb(96,160,176);font-style:italic">// If you&#39;re copy pasting, copy paste these individually!</span><font color="#000000">
</font><span style="color:rgb(96,160,176);font-style:italic">// If you get a null pointer back, use perror(dlerror()) to get a description of the error</span><font color="#000000">
</font><span style="color:rgb(14,132,181);font-weight:bold">dlopen</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(64,112,160)">&quot;/Applications/Xcode-be<wbr>ta.app/Contents/Developer/Plat<wbr>forms/MacOSX.platform/Develope<wbr>r/Library/Frameworks/XCTest.<wbr>framework/Versions/A/XCTest&quot;</span><span style="color:rgb(0,0,0)">,</span><font color="#000000"> </font><span style="color:rgb(14,132,181);font-weight:bold">RTLD_NOW</span><span style="color:rgb(0,0,0)">)</span><font color="#000000">
</font><span style="color:rgb(0,0,0)">dlopen</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(64,112,160)">&quot;/Applications/Xcode-be<wbr>ta.app/Contents/Developer/Tool<wbr>chains/XcodeDefault.xctoolchai<wbr>n/usr/lib/swift/macosx/<wbr>libswiftXCTest.dylib&quot;</span><span style="color:rgb(0,0,0)">,</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">RTLD_NOW</span><span style="color:rgb(0,0,0)">)</span><font color="#000000">
</font><span style="color:rgb(0,112,32);font-weight:bold">import</span><font color="#000000"> </font><span style="color:rgb(14,132,181);font-weight:bold">XCTest</span><font color="#000000">

</font><span style="color:rgb(0,112,32);font-weight:bold">class</span><font color="#000000"> </font><span style="color:rgb(14,132,181);font-weight:bold">MyTest</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">:</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">XCTestCase</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">{</span><font color="#000000"> 
    </font><span style="color:rgb(0,112,32);font-weight:bold">override</span><font color="#000000"> </font><span style="color:rgb(0,112,32);font-weight:bold">func</span><font color="#000000"> </font><span style="color:rgb(6,40,126)">setUp</span><span style="color:rgb(0,0,0)">()</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">{</span><font color="#000000"> 
        </font><span style="color:rgb(0,112,32);font-weight:bold">super</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">setUp</span><span style="color:rgb(0,0,0)">()</span><font color="#000000">
        </font><span style="color:rgb(0,112,32)">print</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(64,112,160)">&quot;Setting up&quot;</span><span style="color:rgb(0,0,0)">)</span><font color="#000000"> 
    </font><span style="color:rgb(0,0,0)">}</span><font color="#000000">
</font><span><font color="#000000">    </font></span><span style="color:rgb(0,112,32);font-weight:bold">override</span><font color="#000000"> </font><span style="color:rgb(0,112,32);font-weight:bold">func</span><font color="#000000"> </font><span style="color:rgb(6,40,126)">tearDown</span><span style="color:rgb(0,0,0)">()</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">{</span><font color="#000000">
        </font><span style="color:rgb(0,112,32);font-weight:bold">super</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">tearDown</span><span style="color:rgb(0,0,0)">()</span><font color="#000000">              
</font><span><font color="#000000">        </font></span><span style="color:rgb(0,112,32)">print</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(64,112,160)">&quot;Tearing down&quot;</span><span style="color:rgb(0,0,0)">)</span><font color="#000000">
    </font><span style="color:rgb(0,0,0)">}</span><font color="#000000">
    </font><span style="color:rgb(0,112,32);font-weight:bold">func</span><font color="#000000"> </font><span style="color:rgb(6,40,126)">testIt</span><span style="color:rgb(0,0,0)">()</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">{</span><font color="#000000"> 
        </font><span style="color:rgb(0,112,32)">print</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(64,112,160)">&quot;I&#39;m never here&quot;</span><span style="color:rgb(0,0,0)">)</span><font color="#000000">
        </font><span style="color:rgb(0,0,0)">XCTAssertTrue</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,112,32);font-weight:bold">false</span><span style="color:rgb(0,0,0)">,</span><font color="#000000"> </font><span style="color:rgb(64,112,160)">&quot;I never see this!&quot;</span><span style="color:rgb(0,0,0)">)</span><font color="#000000"> 
    </font><span style="color:rgb(0,0,0)">}</span><font color="#000000"> 
</font><span style="color:rgb(0,0,0)">}</span><font color="#000000"> 


</font><span style="color:rgb(0,112,32);font-weight:bold">let</span><font color="#000000"> </font><span style="color:rgb(187,96,213)">suite</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">=</span><font color="#000000"> </font><span style="color:rgb(0,0,0)">XCTestSuite</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">name</span><span style="color:rgb(0,0,0)">:</span><font color="#000000"> </font><span style="color:rgb(64,112,160)">&quot;foo&quot;</span><span style="color:rgb(0,0,0)">)</span><font color="#000000">
</font><span style="color:rgb(0,0,0)">suite</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">addTest</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">MyTest</span><span style="color:rgb(0,0,0)">())</span><font color="#000000">
</font><span style="color:rgb(0,0,0)">suite</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">run</span><span style="color:rgb(0,0,0)">()</span></pre></div><div>I see the &quot;setting up&quot; and &quot;tearing down&quot; output, but I never see the print inside -testIt.  Any ideas?</div><div><br></div><div>Thanks, </div><span><font color="#888888"><div>Lou</div><div><br></div></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>