mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-06 06:30:46 +00:00
* Do not enable Win32 threads and locks when using GCC * Fix compiler check when CC has arguments appended * Add NSConstantString literal as global variable to avoid linker error * Make libcurl a hard-dependency on ObjC 2.0 Toolchain * Bump TOOLS_WINDOWS_MSVC_RELEASE_TAG * Remove x86 runner for MSVC toolchain * Add libcurl to MinGW x64 Clang toolchain * MSVC toolchain requires Windows 1903 and newer but windows-2019 runner is Redstone 5 (1809) * MinGW GCC adds .exe suffix * Some tests timeout after 30s. Increase timeout * Mark late unregister as hopeful on Win32 with GCC * Mark NSURL test depending on network connection as hopeful
105 lines
3.2 KiB
Objective-C
105 lines
3.2 KiB
Objective-C
#import <Foundation/NSTask.h>
|
|
#import <Foundation/NSFileHandle.h>
|
|
#import <Foundation/NSFileManager.h>
|
|
#import <Foundation/NSData.h>
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
#import <Foundation/NSError.h>
|
|
#import <Foundation/FoundationErrors.h>
|
|
|
|
#import "ObjectTesting.h"
|
|
|
|
#if !defined(_WIN32)
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
int main()
|
|
{
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
NSError *error;
|
|
NSTask *task;
|
|
NSPipe *outPipe;
|
|
NSFileManager *mgr;
|
|
NSString *helpers;
|
|
NSString *testecho;
|
|
NSString *testcat;
|
|
NSString *processgroup;
|
|
NSFileHandle *outHandle;
|
|
NSData *data = nil;
|
|
|
|
#if defined(_WIN32)
|
|
testecho = @"testecho.exe";
|
|
testcat = @"testcat.exe";
|
|
processgroup = @"processgroup.exe";
|
|
#else
|
|
testecho = @"testecho";
|
|
testcat = @"testcat";
|
|
processgroup = @"processgroup";
|
|
#endif
|
|
|
|
mgr = [NSFileManager defaultManager];
|
|
helpers = [mgr currentDirectoryPath];
|
|
helpers = [helpers stringByAppendingPathComponent: @"Helpers"];
|
|
helpers = [helpers stringByAppendingPathComponent: @"obj"];
|
|
|
|
task = [[NSTask alloc] init];
|
|
outPipe = [[NSPipe pipe] retain];
|
|
[task setLaunchPath: [helpers stringByAppendingPathComponent: testcat]];
|
|
[task setArguments: [NSArray arrayWithObjects: nil]];
|
|
[task setStandardOutput: outPipe];
|
|
outHandle = [outPipe fileHandleForReading];
|
|
|
|
[task launch];
|
|
PASS([task standardOutput] == outPipe, "standardOutput returns pipe");
|
|
data = [outHandle readDataToEndOfFile];
|
|
PASS([data length] > 0, "was able to read data from subtask");
|
|
NSLog(@"Data was %*.*s",
|
|
(int)[data length], (int)[data length], (const char*)[data bytes]);
|
|
[task terminate];
|
|
|
|
task = [[NSTask alloc] init];
|
|
outPipe = [[NSPipe pipe] retain];
|
|
[task setLaunchPath: [helpers stringByAppendingPathComponent: testecho]];
|
|
[task setArguments: [NSArray arrayWithObjects: @"Hello", @"there", nil]];
|
|
[task setStandardOutput: outPipe];
|
|
outHandle = [outPipe fileHandleForReading];
|
|
|
|
[task launch];
|
|
data = [outHandle readDataToEndOfFile];
|
|
PASS([data length] > 0, "was able to read data from subtask");
|
|
NSLog(@"Data was %*.*s",
|
|
(int)[data length], (int)[data length], (const char*)[data bytes]);
|
|
[task terminate];
|
|
|
|
|
|
PASS_EXCEPTION([task launch];, @"NSInvalidArgumentException",
|
|
"raised exception on failed launch")
|
|
[outPipe release];
|
|
[task release];
|
|
|
|
task = [[NSTask alloc] init];
|
|
[task setLaunchPath: [helpers stringByAppendingPathComponent: testcat]];
|
|
[task setArguments: [NSArray arrayWithObjects: nil]];
|
|
[task setCurrentDirectoryPath: @"not-a-directory"];
|
|
PASS([task launchAndReturnError: &error] == NO, "bad directory fails launch")
|
|
PASS(error != nil, "error is returned")
|
|
PASS([error domain] == NSCocoaErrorDomain, "error has expected domain")
|
|
PASS([error code] == NSFileNoSuchFileError, "error has expected code")
|
|
[task release];
|
|
|
|
#if !defined(_WIN32)
|
|
task = [[NSTask alloc] init];
|
|
[task setLaunchPath:
|
|
[helpers stringByAppendingPathComponent: processgroup]];
|
|
[task setArguments: [NSArray arrayWithObjects:
|
|
[NSString stringWithFormat: @"%d", getpgrp()],
|
|
nil]];
|
|
[task launch];
|
|
[task waitUntilExit];
|
|
PASS([task terminationStatus] == 0, "subtask changes process group");
|
|
[task release];
|
|
#endif
|
|
|
|
[arp release];
|
|
|
|
return 0;
|
|
}
|