Skip to content

Commit

Permalink
Adds a test script.
Browse files Browse the repository at this point in the history
Should protect against some of the most rudimentary regressions.
  • Loading branch information
reitzig committed Jul 14, 2018
1 parent 7545bcd commit e8b8b52
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 1 addition & 2 deletions conf.d/sdk.fish
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if test -f "$sdkman_init"
end

# Declare the sdk command for fish
function sdk
function sdk -d "Manage SDKs"
# We need to leave stdin and stdout of sdk free for user interaction.
# So, pipe PATH (which might have changed) through a file.
# Now, getting the exit code of sdk itself is a hassle so pipe it as well.
Expand All @@ -34,7 +34,6 @@ if test -f "$sdkman_init"

set bashPath $bashDump[1]
set sdkStatus $bashDump[2]

# If SDKMAN! succeeded, copy PATH here (might have changed)
if [ $sdkStatus = 0 ]
set newPath (string split : "$bashPath")
Expand Down
40 changes: 40 additions & 0 deletions test/wrapper.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set test_commands \
"sdk" \
"sdk version" \
"sdk list java" \
"sdk update" \
"sdk use ant 1.9.9"
set test_count (count $test_commands)
set check_count (math "3 * $test_count")

set sdk_init "$HOME/.sdkman/bin/sdkman-init.sh"

function checksum -a file
sha256sum $file | cut -d " " -f 1
end

echo "Testing the sdk wrapper"
set failures 0
for sdk_cmd in $test_commands
echo " Testing '$sdk_cmd'"
bash -c "source \"$sdk_init\" && $sdk_cmd > sout_bash; echo \"\$?\" > status_bash; echo "\$PATH" > path_bash"
fish -c "$sdk_cmd > sout_fish; echo \"\$status\" > status_fish; echo "\$PATH" > path_fish"

# Adjust for different path syntax: replace spaces with colons
string join : (string split " " (cat path_fish)) > path_fish

for out in sout status path
if [ (checksum "$out"_bash) != (checksum "$out"_fish) ]
echo " - $out bad:"
diff "$out"_bash "$out"_fish | sed -e 's/^/ /'
set failures (math $failures + 1)
else
echo " - $out ok!"
end
end
echo ""
end

echo "Ran $test_count commands with 3 checks each."
echo "$failures/$check_count checks failed."
exit (math $failures != 0)

0 comments on commit e8b8b52

Please sign in to comment.