Overview
Comment: | utils/objfw-new: Add --test to create tests |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | objfwtest |
Files: | files | file ages | folders |
SHA3-256: |
7f12b95f9cdb5997243b79e4c509a99d |
User & Date: | js on 2024-02-13 02:06:48 |
Other Links: | branch diff | manifest | tags |
Context
2024-02-13
| ||
02:16 | ObjFWTest: Proper plurals in output check-in: d2b609cdd2 user: js tags: objfwtest | |
02:06 | utils/objfw-new: Add --test to create tests check-in: 7f12b95f9c user: js tags: objfwtest | |
01:53 | Migrate OFBlockTests to ObjFWTest check-in: 75bdc50ac9 user: js tags: objfwtest | |
Changes
Modified utils/objfw-new/Makefile from [b67c1400ab] to [8cc4a388ef].
1 2 3 4 5 6 7 8 9 10 11 12 | include ../../extra.mk PROG = objfw-new${PROG_SUFFIX} SRCS = NewApp.m \ NewClass.m \ ObjFWNew.m \ Property.m include ../../buildsys.mk ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 | include ../../extra.mk PROG = objfw-new${PROG_SUFFIX} SRCS = NewApp.m \ NewClass.m \ NewTest.m \ ObjFWNew.m \ Property.m include ../../buildsys.mk ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} |
︙ | ︙ |
Added utils/objfw-new/NewTest.m version [0991f0679f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <errno.h> #import "OFApplication.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOpenItemFailedException.h" void newTest(OFString *name) { OFString *path = [name stringByAppendingPathExtension: @"m"]; OFFile *file = nil; @try { file = [OFFile fileWithPath: path mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @throw e; [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", e.path]; [OFApplication terminateWithStatus: 1]; } [file writeFormat: @"#import <ObjFW/ObjFW.h>\n" @"#import <ObjFWTest/ObjFWTest.h>\n" @"\n" @"@interface %@: OTTestCase\n" @"@end\n" @"\n" @"@implementation %@\n" @"@end\n", name, name]; [file close]; } |
Modified utils/objfw-new/ObjFWNew.m from [5f604351d2] to [0b89b26b9a].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #import "OFString.h" @interface ObjFWNew: OFObject <OFApplicationDelegate> @end extern void newApp(OFString *); extern void newClass(OFString *, OFString *, OFMutableArray *); OF_APPLICATION_DELEGATE(ObjFWNew) static void help(OFStream *stream, bool full, int status) { [stream writeFormat: | > | > < < | > > > | > | | 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 | #import "OFString.h" @interface ObjFWNew: OFObject <OFApplicationDelegate> @end extern void newApp(OFString *); extern void newClass(OFString *, OFString *, OFMutableArray *); extern void newTest(OFString *); OF_APPLICATION_DELEGATE(ObjFWNew) static void help(OFStream *stream, bool full, int status) { [stream writeFormat: @"Usage: %@ --app|--class|--test [--superclass=] [--property=] name" @"\n", [OFApplication programName]]; if (full) { [stream writeString: @"\n"]; [stream writeLine: @"Options:\n" @" -a --app Create a new app\n" @" -c --class Create a new class\n" @" -h --help Show this help\n" @" -p --property= Add a property to the class.\n" @" E.g.: --property='(readonly, " @"nonatomic) id foo'\n" @" -s --superclass= Specify the superclass for the " @"class\n" @" -t --test Create a new test\n"]; } [OFApplication terminateWithStatus: status]; } @implementation ObjFWNew - (void)applicationDidFinishLaunching: (OFNotification *)notification { bool app, class, test; OFString *superclass = nil, *name; OFMutableArray OF_GENERIC(OFString *) *properties = nil; const OFOptionsParserOption options[] = { { 'a', @"app", 0, &app, NULL }, { 'c', @"class", 0, &class, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'p', @"property", 1, NULL, NULL }, { 's', @"superclass", 1, NULL, &superclass }, { 't', @"test", 0, &test, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; if ([OFApplication arguments].count == 0) help(OFStdErr, true, 1); |
︙ | ︙ | |||
90 91 92 93 94 95 96 | case ':': case '=': help(OFStdErr, false, 1); break; } } | > | > > | 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 | case ':': case '=': help(OFStdErr, false, 1); break; } } if (app + class + test != 1 || optionsParser.remainingArguments.count != 1) help(OFStdErr, false, 1); if ((superclass && !class) || (properties != nil && !class)) help(OFStdErr, false, 1); name = optionsParser.remainingArguments.firstObject; if ([name rangeOfString: @"."].location != OFNotFound) { [OFStdErr writeLine: @"Name must not contain dots!"]; [OFApplication terminate]; } if (app) newApp(name); else if (class) newClass(name, superclass, properties); else if (test) newTest(name); else help(OFStdErr, false, 1); [OFApplication terminate]; } @end |