Skip to content

Commit

Permalink
Merge pull request #75 from toshi0383/fix-non-bash-script-failing
Browse files Browse the repository at this point in the history
Fix failing to execute non-shell script
  • Loading branch information
toshi0383 authored Jul 25, 2018
2 parents 5761386 + 7f67520 commit 65d5d37
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Sources/cmdshelf/Commands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,14 @@ final class RunCommand: Command {
}
}()

let args = ["-c", command] + aliasParam.parameters
// [""] workaround for execv ¯\_(ツ)_/¯
let args = [""] + aliasParam.parameters

// Create [UnsafeMutablePointer<Int8>?] carrying NULL at the end.
var cargs: [UnsafeMutablePointer<Int8>?] = args.map { strdup($0) }
cargs.append(UnsafeMutablePointer.init(bitPattern: 0))

poxis_exec("/bin/sh", &cargs)
poxis_exec(command, &cargs)
}
}

Expand Down
2 changes: 1 addition & 1 deletion fixtures/test-005.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
002b
003cd ef
004\"&*><hello
005\
005\\
006world
42 changes: 39 additions & 3 deletions tests/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
STATUS=0
set +e

CMDSHELF=.build/debug/cmdshelf
CMDSHELF=./.build/x86_64-apple-macosx10.10/debug/cmdshelf

before_all() {
cp ~/.cmdshelf.yml ~/.cmdshelf.yml.bk
}

after_all() {
echo All tests finished
cat ~/.cmdshelf.yml
cp ~/.cmdshelf.yml.bk ~/.cmdshelf.yml
}

Expand Down Expand Up @@ -230,13 +229,50 @@ before_each
TEST_014_SH=~/.cmdshelf/remote/_cmdshelf-remote/014.sh
printf "#!/bin/bash\nread line;echo \$line" > $TEST_014_SH
chmod +x $TEST_014_SH
RESULT="(for i in a b; do echo $i | $CMDSHELF run 014.sh; done) | wc -l"
RESULT="$((for i in a b; do echo $i | $CMDSHELF run 014.sh; done) | wc -l)"
if [ $RESULT -ne 2 ];then
echo 'expected 2 but got ' $RESULT
echo 014 FAILED
STATUS=1
fi

## 015: execute non-shell script (perl)
before_each
TEST_015_PL=~/.cmdshelf/remote/_cmdshelf-remote/015.pl
printf "#!/usr/bin/perl -w\nmy (\$a, \$b) = @_;" > $TEST_015_PL

chmod +x $TEST_015_PL
if ! $CMDSHELF run 015.pl
then
echo 015 FAILED
STATUS=1
fi

## 016: execute non-shell script (swift)
before_each
TEST_016_SWIFT=~/.cmdshelf/remote/_cmdshelf-remote/016.swift
printf "#!/usr/bin/swift\nimport Foundation\nprint(ProcessInfo.processInfo.arguments)" > $TEST_016_SWIFT

chmod +x $TEST_016_SWIFT
if ! $CMDSHELF run 016.swift a b c | grep '"a", "b", "c"' > /dev/null 2>&1
then
echo 016 FAILED
STATUS=1
fi

## 017: execute non-shell script (swift binary)
before_each
TEST_017_ECHO_SH=~/.cmdshelf/remote/_cmdshelf-remote/017_echo.sh
printf "#!/bin/bash\necho \$#" > $TEST_017_ECHO_SH
chmod +x $TEST_017_ECHO_SH
TEST_017_SWIFT=~/.cmdshelf/remote/_cmdshelf-remote/017_cmdshelf
cp $CMDSHELF $TEST_017_SWIFT

if [ 3 -ne $($CMDSHELF run 017_cmdshelf run 017_echo.sh a b c) ];then
echo 017 FAILED
STATUS=1
fi

# Cleanup
after_all

Expand Down

0 comments on commit 65d5d37

Please sign in to comment.