Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 359 lines (305 sloc) 16.126 kb
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
//
// GBApplicationSettingsProviderTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 9.12.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//

#import "DDCliApplication.h"
#import "DDGetoptLongParser.h"
#import "GBApplicationSettingsProvider.h"
#import "GBAppledocApplication.h"

@interface GBAppledocApplicationTesting : GHTestCase

- (GBApplicationSettingsProvider *)settingsByRunningWithArgs:(NSString *)first, ... NS_REQUIRES_NIL_TERMINATION;

@end

@implementation GBAppledocApplicationTesting

#pragma mark Paths settings testing

- (void)testOutput_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--output", @"path", nil];
// verify
assertThat(settings.outputPath, is(@"path"));
}

- (void)testTemplates_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--templates", @"path", nil];
// verify
assertThat(settings.templatesPath, is(@"path"));
}

- (void)testDocsetInstallPath_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-install-path", @"path", nil];
// verify
assertThat(settings.docsetInstallPath, is(@"path"));
}

- (void)testDocsetUtilPath_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docsetutil-path", @"path", nil];
// verify
assertThat(settings.docsetUtilPath, is(@"path"));
}

- (void)testIgnore_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--ignore", @"path", nil];
// verify
assertThatInteger([settings.ignoredPaths count], equalToInteger(1));
assertThatBool([settings.ignoredPaths containsObject:@"path"], equalToBool(YES));
}

- (void)testIgnore_shouldAssignMutlipleValuesToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--ignore", @"path1", @"--ignore", @"path2", @"--ignore", @"path3", nil];
// verify
assertThatInteger([settings.ignoredPaths count], equalToInteger(3));
assertThatBool([settings.ignoredPaths containsObject:@"path1"], equalToBool(YES));
assertThatBool([settings.ignoredPaths containsObject:@"path2"], equalToBool(YES));
assertThatBool([settings.ignoredPaths containsObject:@"path3"], equalToBool(YES));
}

#pragma mark Project settings testing

- (void)testProjectName_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--project-name", @"value", nil];
// verify
assertThat(settings.projectName, is(@"value"));
}

- (void)testProjectVersion_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--project-version", @"value", nil];
// verify
assertThat(settings.projectVersion, is(@"value"));
}

- (void)testProjectCompany_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--project-company", @"value", nil];
// verify
assertThat(settings.projectCompany, is(@"value"));
}

- (void)testCompanyIdentifier_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--company-id", @"value", nil];
// verify
assertThat(settings.companyIdentifier, is(@"value"));
}

#pragma mark Behavior settings testing

- (void)testCreateHTML_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--create-html", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-create-html", nil];
// verify
assertThatBool(settings1.createHTML, equalToBool(YES));
assertThatBool(settings2.createHTML, equalToBool(NO));
}

- (void)testCreateDocSet_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--create-docset", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-create-docset", nil];
// verify
assertThatBool(settings1.createDocSet, equalToBool(YES));
assertThatBool(settings2.createDocSet, equalToBool(NO));
}

- (void)testInstallDocSet_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--install-docset", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-install-docset", nil];
// verify
assertThatBool(settings1.installDocSet, equalToBool(YES));
assertThatBool(settings2.installDocSet, equalToBool(NO));
}

- (void)testKeepUndocumentedObjects_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--keep-undocumented-objects", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-keep-undocumented-objects", nil];
// verify
assertThatBool(settings1.keepUndocumentedObjects, equalToBool(YES));
assertThatBool(settings2.keepUndocumentedObjects, equalToBool(NO));
}

- (void)testKeepUndocumentedMembers_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--keep-undocumented-members", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-keep-undocumented-members", nil];
// verify
assertThatBool(settings1.keepUndocumentedMembers, equalToBool(YES));
assertThatBool(settings2.keepUndocumentedMembers, equalToBool(NO));
}

- (void)testFindUndocumentedMembersDocumentation_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--search-undocumented-doc", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-search-undocumented-doc", nil];
// verify
assertThatBool(settings1.findUndocumentedMembersDocumentation, equalToBool(YES));
assertThatBool(settings2.findUndocumentedMembersDocumentation, equalToBool(NO));
}

- (void)testMergeCategoriesToClasses_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--merge-categories", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-merge-categories", nil];
// verify
assertThatBool(settings1.mergeCategoriesToClasses, equalToBool(YES));
assertThatBool(settings2.mergeCategoriesToClasses, equalToBool(NO));
}

- (void)testKeepMergedCategoriesSections_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--keep-merged-sections", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-keep-merged-sections", nil];
// verify
assertThatBool(settings1.keepMergedCategoriesSections, equalToBool(YES));
assertThatBool(settings2.keepMergedCategoriesSections, equalToBool(NO));
}

- (void)testPrefixMergedCategoriesSectionsWithCategoryName_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--prefix-merged-sections", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-prefix-merged-sections", nil];
// verify
assertThatBool(settings1.prefixMergedCategoriesSectionsWithCategoryName, equalToBool(YES));
assertThatBool(settings2.prefixMergedCategoriesSectionsWithCategoryName, equalToBool(NO));
}

#pragma mark Warnings settings testing

- (void)testWarnOnMissingOutputPath_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--warn-missing-output-path", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-warn-missing-output-path", nil];
// verify
assertThatBool(settings1.warnOnMissingOutputPathArgument, equalToBool(YES));
assertThatBool(settings2.warnOnMissingOutputPathArgument, equalToBool(NO));
}

- (void)testWarnOnMissingCompanyIdentifier_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--warn-missing-company-id", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-warn-missing-company-id", nil];
// verify
assertThatBool(settings1.warnOnMissingCompanyIdentifier, equalToBool(YES));
assertThatBool(settings2.warnOnMissingCompanyIdentifier, equalToBool(NO));
}

- (void)testWarnOnUndocumentedObject_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--warn-undocumented-object", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-warn-undocumented-object", nil];
// verify
assertThatBool(settings1.warnOnUndocumentedObject, equalToBool(YES));
assertThatBool(settings2.warnOnUndocumentedObject, equalToBool(NO));
}

- (void)testWarnOnUndocumentedMember_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--warn-undocumented-member", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-warn-undocumented-member", nil];
// verify
assertThatBool(settings1.warnOnUndocumentedMember, equalToBool(YES));
assertThatBool(settings2.warnOnUndocumentedMember, equalToBool(NO));
}

#pragma mark Documentation set settings testing

- (void)testDocSetBudnleIdentifier_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-bundle-id", @"value", nil];
// verify
assertThat(settings.docsetBundleIdentifier, is(@"value"));
}

- (void)testDocSetBundleName_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-bundle-name", @"value", nil];
// verify
assertThat(settings.docsetBundleName, is(@"value"));
}

- (void)testDocSetDescription_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-desc", @"value", nil];
// verify
assertThat(settings.docsetDescription, is(@"value"));
}

- (void)testDocSetCopyright_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-copyright", @"value", nil];
// verify
assertThat(settings.docsetCopyrightMessage, is(@"value"));
}

- (void)testDocSetFeedName_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-feed-name", @"value", nil];
// verify
assertThat(settings.docsetFeedName, is(@"value"));
}

- (void)testDocSetFeedURL_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-feed-url", @"value", nil];
// verify
assertThat(settings.docsetFeedURL, is(@"value"));
}

- (void)testDocSetFallbackURL_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-fallback-url", @"value", nil];
// verify
assertThat(settings.docsetFallbackURL, is(@"value"));
}

- (void)testDocSetPublisherIdentifier_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-publisher-id", @"value", nil];
// verify
assertThat(settings.docsetPublisherIdentifier, is(@"value"));
}

- (void)testDocSetPublisherName_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-publisher-name", @"value", nil];
// verify
assertThat(settings.docsetPublisherName, is(@"value"));
}

- (void)testDocSetMinXcodeVersion_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-min-xcode-version", @"value", nil];
// verify
assertThat(settings.docsetMinimumXcodeVersion, is(@"value"));
}

- (void)testDocSetPlatformFamily_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-platform-family", @"value", nil];
// verify
assertThat(settings.docsetPlatformFamily, is(@"value"));
}

- (void)testDocSetCertificateIssuer_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-cert-issuer", @"value", nil];
// verify
assertThat(settings.docsetCertificateIssuer, is(@"value"));
}

- (void)testDocSetCertificateSigner_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings = [self settingsByRunningWithArgs:@"--docset-cert-signer", @"value", nil];
// verify
assertThat(settings.docsetCertificateSigner, is(@"value"));
}

#pragma mark Creation methods

- (GBApplicationSettingsProvider *)settingsByRunningWithArgs:(NSString *)first, ... {
// Basically this method allows testing whether the application properly maps command line arguments to settings. The method is a hack - it partially duplicates the internal workings of DDGetoptLongParser. First thing it constructs GBAppledocApplication object and injects it custom settings. Then it converts the given list of command line options to appropriate KVC messages and sends them to the application object - it uses DDGetoptLongParser to get the name of the KVC key for each option (some additions were required in order to expose the method that converts arguments to keys). As application more or less maps each command line option to specific property of it's settings, we can then use the injected settings to check whether all properties have correct values.
// Note that this might easily be broken if internal workings of DDCli changes. In fact at first I did try to use DDCliRunApplication, but this only worked the first time used, it failed to extract options in all subsequent tests. And even then, DDCli code required some additions so that I was able passing it arbitrary list of arguments. On the other hand, the whole DDCli source code copy is used by appledoc, so any change to it is predictable...
// Also note that we could go without changing any of DDCli code by simply using keys instead of command line arguments, but that would make unit tests less obvious... Another way would be to create the code that converts cli argument to key manually, but current solution seemed quite acceptable.

// get arguments
NSMutableArray *arguments = [NSMutableArray array];
va_list args;
va_start(args, first);
for (NSString *arg=first; arg != nil; arg=va_arg(args, NSString*)) {
[arguments addObject:arg];
}
va_end(args);

// setup the application and inject settings to it.
GBAppledocApplication *application = [[[GBAppledocApplication alloc] init] autorelease];
GBApplicationSettingsProvider *result = [GBApplicationSettingsProvider provider];
[application setValue:result forKey:@"settings"];

// send all KVC messages for all options
for (NSUInteger i=0; i<[arguments count]; i++) {
NSString *arg = [arguments objectAtIndex:i];
if ([arg hasPrefix:@"--"]) {
// get the key corresponding to the argument
NSString *key = [DDGetoptLongParser keyFromOption:arg];

// if we have a value following, use it for KVC, otherwise just send YES
if (i < [arguments count] - 1) {
NSString *value = [arguments objectAtIndex:i+1];
if (![value hasPrefix:@"--"]) {
[application setValue:value forKey:key];
i++;
continue;
}
}
[application setValue:[NSNumber numberWithBool:YES] forKey:key];
}
}

// return settings for validation these should now contain all values application passed from KVC messages
return result;
}

@end
Something went wrong with that request. Please try again.