Skip to content

Commit

Permalink
Fix Cardano CLI tests on MacOS:
Browse files Browse the repository at this point in the history
    * Introduce DATE and SED environment variables to switch betweed date
      and gdate; and sed and gsed for MacOS/Linux compatibility.
    * Use xargs to strip whitespace from either side of the line count so
      that line count comparisions work on MacOS
    * Use bash instead of sh to avoid shell lint error on used of type
      shell command
  • Loading branch information
newhoggy authored and erikd committed Jul 7, 2020
1 parent ced3026 commit 0b6eecb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion cardano-cli/test/cli/core/common
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash -eu

OS=$(uname -s)

case $OS in
Darwin ) export DATE=gdate; export SED=gsed;;
* ) export DATE=date ; export SED=sed ;; esac

if test "${CARDANO_CLI:-x}" = "x" ; then
# Need this for when the test scripts are run directly instead of via the
# Haskell test runner.
Expand Down Expand Up @@ -65,7 +71,7 @@ assert_string () {
}

assert_line_count () {
line_count=$(wc -l < "$2")
line_count=$(wc -l < "$2" | xargs)
if test "${line_count}" != "$1" ; then
echo "$2: line count is ${line_count} "
cat "$2"
Expand Down
10 changes: 5 additions & 5 deletions cardano-cli/test/cli/genesis-create/run
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ setup_data_dir "${testname}"

OUTPUT_JSON="${TEST_DIR}/genesis.json"

start_time=$(TZ=UTC date --iso-8601=seconds | sed 's/+.*/Z/')
start_time=$(TZ=UTC $DATE --iso-8601=seconds | $SED 's/+.*/Z/')

cp "${DATA_DIR}/genesis.spec.json" "${TEST_DIR}/"

# Random number for the total supply.
supply=$(head -100 /dev/urandom | cksum | sed 's/ .*//')
supply=$(head -100 /dev/urandom | cksum | $SED 's/ .*//')

# Random number for the number of genesis delegates.
seconds=$(date +"%s")
seconds=$($DATE +"%s")
gendlg_count=$(( 4 + seconds % 16))

error=0
Expand Down Expand Up @@ -69,14 +69,14 @@ if test "${check_supply}" != "${supply}" ; then

jq '.genDelegs' < "${OUTPUT_JSON}" | grep ': {' > "${TEST_DIR}/genesis-delegate.pairs"

keyhash_count=$(sed 's/:.*//' < "${TEST_DIR}/genesis-delegate.pairs" | sort | uniq | wc -l)
keyhash_count=$(sed 's/:.*//' < "${TEST_DIR}/genesis-delegate.pairs" | sort | uniq | wc -l | xargs)
if test "${keyhash_count}" != "${gendlg_count}" ; then
echo "Genesis keyhashes are not unique."
cat "${TEST_DIR}/genesis-delegate.pairs"
error=1
fi

keyhash_delegate_count=$(sort "${TEST_DIR}/genesis-delegate.pairs" | uniq | wc -l)
keyhash_delegate_count=$(sort "${TEST_DIR}/genesis-delegate.pairs" | uniq | wc -l | xargs)
if test "${keyhash_delegate_count}" != "${gendlg_count}" ; then
echo "Genesis delegate keyhashes are not unique (${keyhash_delegate_count} != ${gendlg_count})."
cat "${TEST_DIR}/genesis-delegate.pairs"
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/test/cli/shellcheck/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -u
#!/bin/bash -u

cwd=$(dirname "$0")

Expand Down

0 comments on commit 0b6eecb

Please sign in to comment.