Skip to content

Instantly share code, notes, and snippets.

@ob
Created November 8, 2019 22:52

Revisions

  1. ob created this gist Nov 8, 2019.
    51 changes: 51 additions & 0 deletions bp-test-dumper.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #import <Foundation/Foundation.h>
    #import <XCTest/XCTest.h>

    @interface TestDumper : NSObject

    @end

    @implementation TestDumper

    + (void)load {
    NSBundle *mainBundle = [NSBundle mainBundle];
    NSString *pluginsPath = [mainBundle builtInPlugInsPath];
    NSArray* xcTests = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pluginsPath error:Nil];
    for (NSString *xcTestBundlePath in xcTests) {
    NSString *ext = [xcTestBundlePath pathExtension];
    if (![ext isEqual:@"xctest"]) {
    NSLog(@"Skipping %@ - %@", xcTestBundlePath, ext);
    continue;
    }
    NSString *path = [pluginsPath stringByAppendingPathComponent:xcTestBundlePath];
    NSLog(@"Loading %@", path);
    NSBundle *bundle = [NSBundle bundleWithPath:path];
    if (!bundle) {
    printf("bundle failed to load!\n");
    perror("bundle");
    exit(1);
    }
    NSError *err;
    if (![bundle loadAndReturnError:&err]) {
    NSLog(@"Failed to load bundle: %@: %@", path, err);
    }
    }

    XCTestSuite *dtest = [XCTestSuite defaultTestSuite];
    if (!dtest) {
    printf("failed in XCTestSuite\n");
    exit(1);
    }
    for (XCTestSuite *testSuite in [dtest tests]) {
    NSLog(@"Loaded %@", [testSuite name]);
    for (XCTestSuite *ts in [testSuite tests]) {
    NSLog(@"Loaded %@", [ts name]);
    for (XCTest *t in [ts tests]) {
    NSLog(@"Test: %@", [t name]);
    }
    }
    }
    // don't actually run the app
    exit(0);
    }
    @end