Index: utils/objfw-new/Makefile ================================================================== --- utils/objfw-new/Makefile +++ utils/objfw-new/Makefile @@ -1,10 +1,11 @@ include ../../extra.mk PROG = objfw-new${PROG_SUFFIX} SRCS = NewApp.m \ NewClass.m \ + NewTest.m \ ObjFWNew.m \ Property.m include ../../buildsys.mk ADDED utils/objfw-new/NewTest.m Index: utils/objfw-new/NewTest.m ================================================================== --- utils/objfw-new/NewTest.m +++ utils/objfw-new/NewTest.m @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 + +#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 \n" + @"#import \n" + @"\n" + @"@interface %@: OTTestCase\n" + @"@end\n" + @"\n" + @"@implementation %@\n" + @"@end\n", + name, name]; + + [file close]; +} Index: utils/objfw-new/ObjFWNew.m ================================================================== --- utils/objfw-new/ObjFWNew.m +++ utils/objfw-new/ObjFWNew.m @@ -25,49 +25,53 @@ @interface ObjFWNew: OFObject @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 [--superclass=] [--property=] name\n", + @"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" - @" -s --superclass= Specify the superclass for the " - @"class\n" @" -p --property= Add a property to the class.\n" @" E.g.: --property='(readonly, " - @"nonatomic) id foo'"]; + @"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; + 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 }, - { 's', @"superclass", 1, NULL, &superclass }, { 'p', @"property", 1, NULL, NULL }, + { 's', @"superclass", 1, NULL, &superclass }, + { 't', @"test", 0, &test, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; @@ -92,11 +96,12 @@ help(OFStdErr, false, 1); break; } } - if ((app ^ class) != 1 || optionsParser.remainingArguments.count != 1) + if (app + class + test != 1 || + optionsParser.remainingArguments.count != 1) help(OFStdErr, false, 1); if ((superclass && !class) || (properties != nil && !class)) help(OFStdErr, false, 1); @@ -108,11 +113,13 @@ if (app) newApp(name); else if (class) newClass(name, superclass, properties); + else if (test) + newTest(name); else help(OFStdErr, false, 1); [OFApplication terminate]; } @end