PageRenderTime 80ms CodeModel.GetById 37ms app.highlight 40ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/Core/KSCommandRunnerTest.m

http://macfuse.googlecode.com/
Objective C | 114 lines | 81 code | 18 blank | 15 comment | 10 complexity | 910cedab49e5996231d848fb813f3c65 MD5 | raw file
  1// Copyright 2008 Google Inc.
  2//
  3// Licensed under the Apache License, Version 2.0 (the "License");
  4// you may not use this file except in compliance with the License.
  5// You may obtain a copy of the License at
  6//
  7//     http://www.apache.org/licenses/LICENSE-2.0
  8//
  9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15#import <SenTestingKit/SenTestingKit.h>
 16#import "KSCommandRunner.h"
 17
 18
 19@interface KSCommandRunnerTest : SenTestCase
 20@end
 21
 22
 23@implementation KSCommandRunnerTest
 24
 25- (void)testBasic {
 26  KSTaskCommandRunner *cmd = [KSTaskCommandRunner commandRunner];
 27  STAssertNotNil(cmd, nil);
 28  
 29  NSString *output = nil;
 30  int rc = 0;
 31  
 32  rc = [cmd runCommand:@"/bin/ls"
 33              withArgs:[NSArray arrayWithObjects:@"-F", @"/tmp", nil]
 34           environment:nil
 35                output:&output];
 36  STAssertTrue(rc == 0, nil);
 37  STAssertNotNil(output, nil);
 38  STAssertEqualObjects(output, @"/tmp@\n", nil);
 39  
 40  output = nil;
 41  rc = [cmd runCommand:@"/blah/foo/bar/baz/FAKE/PATH"
 42              withArgs:[NSArray arrayWithObjects:@"-F", @"/tmp", nil]
 43           environment:nil
 44                output:&output];
 45  STAssertTrue(rc != 0, nil);
 46  STAssertNil(output, nil);
 47  
 48  output = nil;
 49  rc = [cmd runCommand:@"/bin/ls"
 50              withArgs:[NSArray arrayWithObjects:@"-F", @"/tmp", nil]
 51           environment:nil
 52                output:nil];
 53  STAssertTrue(rc == 0, nil);
 54  STAssertNil(output, nil);
 55  
 56  output = nil;
 57  rc = [cmd runCommand:@"/bin/ls"
 58              withArgs:nil
 59           environment:nil
 60                output:&output];
 61  STAssertTrue(rc == 0, nil);
 62  STAssertNotNil(output, nil);
 63  
 64  output = nil;
 65  rc = [cmd runCommand:@"/usr/bin/env"
 66              withArgs:nil
 67           environment:[NSDictionary dictionaryWithObject:@"blah" forKey:@"KS_COMMAND_RUNNER_TEST"]
 68                output:&output];
 69  STAssertTrue(rc == 0, nil);
 70  STAssertNotNil(output, nil);
 71  NSRange r = [output rangeOfString:@"KS_COMMAND_RUNNER_TEST=blah"];
 72  STAssertTrue(r.location != NSNotFound, nil);
 73  
 74  output = nil;
 75  rc = [cmd runCommand:@"/bin/sh"
 76              withArgs:[NSArray arrayWithObjects:@"-c", @"exit 1", nil]
 77           environment:nil
 78                output:&output];
 79  STAssertTrue(rc == 1, nil);
 80  
 81  output = nil;
 82  rc = [cmd runCommand:nil
 83              withArgs:nil
 84           environment:nil
 85                output:&output];
 86  STAssertTrue(rc == 1, nil);
 87}
 88
 89- (void)testError {
 90  KSTaskCommandRunner *cmd = [KSTaskCommandRunner commandRunner];
 91
 92  // Successful command should have an empty stderror.
 93  int rc = 0;
 94  NSString *output;
 95  NSString *stderror;
 96  rc = [cmd runCommand:@"/bin/ls"
 97              withArgs:[NSArray arrayWithObjects:@"-F", @"/tmp", nil]
 98           environment:nil
 99                output:&output
100              stdError:&stderror];
101  STAssertEquals(rc, 0, nil);
102  STAssertEquals([stderror length], 0u, nil);
103
104  // Unsuccessful command should have stuff in the error
105  rc = [cmd runCommand:@"/bin/ls"
106              withArgs:[NSArray arrayWithObject:@"--fnordbork"]
107           environment:nil
108                output:&output
109              stdError:&stderror];
110  STAssertTrue(rc != 0, nil);
111  STAssertFalse([stderror length] == 0, nil);
112}
113
114@end