From 66dc6e0ac5727e6b33b67716960524c6a8fd7021 Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 3 Jan 2020 12:23:07 +0100 Subject: [PATCH 1/9] Added simple date functions and added dates to logging --- docker/shellcheck/Dockerfile | 1 + src/bash/dates/dates.sh | 9 +++++++++ src/bash/dates/local.sh | 30 ++++++++++++++++++++++++++++++ src/bash/dates/utc.sh | 30 ++++++++++++++++++++++++++++++ src/bash/logging/.internal.sh | 13 +++++++------ 5 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/bash/dates/dates.sh create mode 100644 src/bash/dates/local.sh create mode 100644 src/bash/dates/utc.sh diff --git a/docker/shellcheck/Dockerfile b/docker/shellcheck/Dockerfile index 1c67f74..b0a65ce 100644 --- a/docker/shellcheck/Dockerfile +++ b/docker/shellcheck/Dockerfile @@ -5,6 +5,7 @@ RUN apt update && \ apt install -y shellcheck RUN echo '#!/usr/bin/env bash\n\ +shopt -s dotglob\n\ for f in $(ls /srv/crucible/bash/**/*)\n\ do\n\ if [ -f $f ]; then shellcheck $f -x -s bash; fi\n\ diff --git a/src/bash/dates/dates.sh b/src/bash/dates/dates.sh new file mode 100644 index 0000000..2c13fd2 --- /dev/null +++ b/src/bash/dates/dates.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +### CRUCIBLE META DATA ### +# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_AUTHOR=StealthyCoder +# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +### CRUCIBLE META DATA ### + +require dates/utc +require dates/local diff --git a/src/bash/dates/local.sh b/src/bash/dates/local.sh new file mode 100644 index 0000000..33e9d1f --- /dev/null +++ b/src/bash/dates/local.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +### CRUCIBLE META DATA ### +# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_AUTHOR=StealthyCoder +# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +### CRUCIBLE META DATA ### + +function dates.local.now { + date +} + +function dates.local.now.timestamp { + date +%s +} + +function dates.local.rfc3339.ns { + date --rfc-3339=ns +} + +function dates.local.rfc3339.seconds { + date --rfc-3339=seconds +} + +function dates.local.rfc3339.date { + date --rfc-3339=date +} + +function dates.local.email { + date --rfc-email +} \ No newline at end of file diff --git a/src/bash/dates/utc.sh b/src/bash/dates/utc.sh new file mode 100644 index 0000000..a568782 --- /dev/null +++ b/src/bash/dates/utc.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +### CRUCIBLE META DATA ### +# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_AUTHOR=StealthyCoder +# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +### CRUCIBLE META DATA ### + +function dates.utc.now { + date -u +} + +function dates.utc.now.timestamp { + date -u +%s +} + +function dates.utc.rfc3339.ns { + date -u --rfc-3339=ns +} + +function dates.utc.rfc3339.seconds { + date -u --rfc-3339=seconds +} + +function dates.utc.rfc3339.date { + date -u --rfc-3339=date +} + +function dates.utc.email { + date -u --rfc-email +} \ No newline at end of file diff --git a/src/bash/logging/.internal.sh b/src/bash/logging/.internal.sh index 023748f..eeb42bb 100644 --- a/src/bash/logging/.internal.sh +++ b/src/bash/logging/.internal.sh @@ -6,6 +6,7 @@ ### CRUCIBLE META DATA ### require logging/.constants +require dates/utc function _echo { echo -e "$1" @@ -14,22 +15,22 @@ function _echo { function _format { case $1 in INFO) - _echo "$(__cyan)[ $1 ] $2 $(__reset)" + _echo "$(__cyan)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" ;; DEBUG) - _echo "$(__blue)[ $1 ] $2 $(__reset)" + _echo "$(__blue)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" ;; WARNING) - _echo "$(__yellow)[ $1 ] $2 $(__reset)" + _echo "$(__yellow)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" ;; ERROR) - _echo "$(__red)[ $1 ] $2 $(__reset)" + _echo "$(__red)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" ;; SUCCESS) - _echo "$(__green)[ $1 ] $2 $(__reset)" + _echo "$(__green)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" ;; *) - _echo "$(__cyan)[ $1 ] $2 $(__reset)" + _echo "$(__cyan)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" ;; esac } From 16a8d72485a7fa04d427bbc74254f0a24fadc210 Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 3 Jan 2020 12:29:58 +0100 Subject: [PATCH 2/9] Added iso8601 functions and changed logging to it --- src/bash/dates/local.sh | 20 ++++++++++++++++++++ src/bash/dates/utc.sh | 20 ++++++++++++++++++++ src/bash/logging/.internal.sh | 12 ++++++------ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/bash/dates/local.sh b/src/bash/dates/local.sh index 33e9d1f..0b03a0e 100644 --- a/src/bash/dates/local.sh +++ b/src/bash/dates/local.sh @@ -27,4 +27,24 @@ function dates.local.rfc3339.date { function dates.local.email { date --rfc-email +} + +function dates.local.iso8601.ns { + date --iso-8601=ns +} + +function dates.local.is8601.seconds { + date --iso-8601=seconds +} + +function dates.local.iso8601.minutes { + date --iso-8601=minutes +} + +function dates.local.iso8601.hours { + date --iso-8601=hours +} + +function dates.local.iso8601.date { + date --iso-8601=date } \ No newline at end of file diff --git a/src/bash/dates/utc.sh b/src/bash/dates/utc.sh index a568782..f0240d7 100644 --- a/src/bash/dates/utc.sh +++ b/src/bash/dates/utc.sh @@ -27,4 +27,24 @@ function dates.utc.rfc3339.date { function dates.utc.email { date -u --rfc-email +} + +function dates.utc.iso8601.ns { + date -u --iso-8601=ns +} + +function dates.utc.is8601.seconds { + date -u --iso-8601=seconds +} + +function dates.utc.iso8601.minutes { + date -u --iso-8601=minutes +} + +function dates.utc.iso8601.hours { + date -u --iso-8601=hours +} + +function dates.utc.iso8601.date { + date -u --iso-8601=date } \ No newline at end of file diff --git a/src/bash/logging/.internal.sh b/src/bash/logging/.internal.sh index eeb42bb..b0c3918 100644 --- a/src/bash/logging/.internal.sh +++ b/src/bash/logging/.internal.sh @@ -15,22 +15,22 @@ function _echo { function _format { case $1 in INFO) - _echo "$(__cyan)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" + _echo "$(__cyan)[ $1 ] $(dates.utc.iso8601.ns) $2 $(__reset)" ;; DEBUG) - _echo "$(__blue)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" + _echo "$(__blue)[ $1 ] $(dates.utc.iso8601.ns) $2 $(__reset)" ;; WARNING) - _echo "$(__yellow)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" + _echo "$(__yellow)[ $1 ] $(dates.utc.iso8601.ns) $2 $(__reset)" ;; ERROR) - _echo "$(__red)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" + _echo "$(__red)[ $1 ] $(dates.utc.iso8601.ns) $2 $(__reset)" ;; SUCCESS) - _echo "$(__green)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" + _echo "$(__green)[ $1 ] $(dates.utc.iso8601.ns) $2 $(__reset)" ;; *) - _echo "$(__cyan)[ $1 ] $(dates.utc.rfc3339.ns) $2 $(__reset)" + _echo "$(__cyan)[ $1 ] $(dates.utc.iso8601.ns) $2 $(__reset)" ;; esac } From 031ef57a82471479ed9490b8305a09be65dea95d Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 3 Jan 2020 12:45:12 +0100 Subject: [PATCH 3/9] Added optional params to be used for testing --- src/bash/dates/local.sh | 88 +++++++++++++++++++++++++++++++++++------ src/bash/dates/utc.sh | 80 +++++++++++++++++++++++++++++++------ 2 files changed, 145 insertions(+), 23 deletions(-) diff --git a/src/bash/dates/local.sh b/src/bash/dates/local.sh index 0b03a0e..ecda6db 100644 --- a/src/bash/dates/local.sh +++ b/src/bash/dates/local.sh @@ -6,45 +6,111 @@ ### CRUCIBLE META DATA ### function dates.local.now { - date + if [ -z "$1" ] + then + date + else + date "$1" + fi + } function dates.local.now.timestamp { - date +%s + if [ -z "$1" ] + then + date +%s + else + date +%s "$1" + fi + } function dates.local.rfc3339.ns { - date --rfc-3339=ns + if [ -z "$1" ] + then + date --rfc-3339=ns + else + date --rfc-3339=ns "$1" + fi + } function dates.local.rfc3339.seconds { - date --rfc-3339=seconds + if [ -z "$1" ] + then + date --rfc-3339=seconds + else + date --rfc-3339=seconds "$1" + fi + } function dates.local.rfc3339.date { - date --rfc-3339=date + if [ -z "$1" ] + then + date --rfc-3339=date + else + date --rfc-3339=date "$1" + fi + } function dates.local.email { - date --rfc-email + if [ -z "$1" ] + then + date --rfc-email + else + date --rfc-email "$1" + fi + } function dates.local.iso8601.ns { - date --iso-8601=ns + if [ -z "$1" ] + then + date --iso-8601=ns + else + date --iso-8601=ns "$1" + fi + } function dates.local.is8601.seconds { - date --iso-8601=seconds + if [ -z "$1" ] + then + date --iso-8601=seconds + else + date --iso-8601=seconds "$1" + fi + } function dates.local.iso8601.minutes { - date --iso-8601=minutes + if [ -z "$1" ] + then + date --iso-8601=minutes + else + date --iso-8601=minutes "$1" + fi + } function dates.local.iso8601.hours { - date --iso-8601=hours + if [ -z "$1" ] + then + date --iso-8601=hours + else + date --iso-8601=hours "$1" + fi + } function dates.local.iso8601.date { - date --iso-8601=date + if [ -z "$1" ] + then + date --iso-8601=date + else + date --iso-8601=date "$1" + fi + } \ No newline at end of file diff --git a/src/bash/dates/utc.sh b/src/bash/dates/utc.sh index f0240d7..a2f9f3a 100644 --- a/src/bash/dates/utc.sh +++ b/src/bash/dates/utc.sh @@ -6,45 +6,101 @@ ### CRUCIBLE META DATA ### function dates.utc.now { - date -u + if [ -z "$1" ] + then + date -u + else + date -u "$1" + fi + } function dates.utc.now.timestamp { - date -u +%s + if [ -z "$1" ] + then + date -u +%s + else + date -u +%s "$1" + fi } function dates.utc.rfc3339.ns { - date -u --rfc-3339=ns + if [ -z "$1" ] + then + date -u --rfc-3339=ns + else + date -u --rfc-3339=ns "$1" + fi } function dates.utc.rfc3339.seconds { - date -u --rfc-3339=seconds + if [ -z "$1" ] + then + date -u --rfc-3339=seconds + else + date -u --rfc-3339=seconds "$1" + fi } function dates.utc.rfc3339.date { - date -u --rfc-3339=date + if [ -z "$1" ] + then + date -u --rfc-3339=date + else + date -u --rfc-3339=date "$1" + fi } function dates.utc.email { - date -u --rfc-email + if [ -z "$1" ] + then + date -u --rfc-email + else + date -u --rfc-email "$1" + fi } function dates.utc.iso8601.ns { - date -u --iso-8601=ns + if [ -z "$1" ] + then + date -u --iso-8601=ns + else + date -u --iso-8601=ns "$1" + fi } function dates.utc.is8601.seconds { - date -u --iso-8601=seconds + if [ -z "$1" ] + then + date -u --iso-8601=seconds + else + date -u --iso-8601=seconds "$1" + fi } function dates.utc.iso8601.minutes { - date -u --iso-8601=minutes + if [ -z "$1" ] + then + date -u --iso-8601=minutes + else + date -u --iso-8601=minutes "$1" + fi } function dates.utc.iso8601.hours { - date -u --iso-8601=hours + if [ -z "$1" ] + then + date -u --iso-8601=hours + else + date -u --iso-8601=hours "$1" + fi } function dates.utc.iso8601.date { - date -u --iso-8601=date -} \ No newline at end of file + if [ -z "$1" ] + then + date -u --iso-8601=date + else + date -u --iso-8601=date "$1" + fi +} \ No newline at end of file From 53839eae1d39f1051c6d573b8dfcb3bb88d5e66c Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Sun, 5 Jan 2020 10:49:56 +0100 Subject: [PATCH 4/9] Fixed logging tests --- test/bash/logging/logging.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/bash/logging/logging.sh b/test/bash/logging/logging.sh index 8bb22b3..cfa263c 100644 --- a/test/bash/logging/logging.sh +++ b/test/bash/logging/logging.sh @@ -51,7 +51,7 @@ function logging.logging.info { intro "logging.logging.info" local msg msg="$(logging.info Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;86m[ INFO ] Cookie [0m" || fail "Message was wrong format $msg" + [[ "$msg" =~ \[38\;5\;86m\[\ INFO\ \].*Cookie ]] || fail "Message was wrong format $msg" success } @@ -63,7 +63,7 @@ function logging.logging.debug { logging.set_level "$(logging.level.debug)" msg="$(logging.debug Cookie | tr -d -C '[:print:]')" - test "$msg" = "[34m[ DEBUG ] Cookie [0m" || fail "Message was wrong format $msg" + [[ "$msg" =~ \[34m\[\ DEBUG\ \].*Cookie ]] || fail "Message was wrong format $msg" success unset CRUCIBLE_LOGGING_LEVEL } @@ -72,7 +72,7 @@ function logging.logging.error { intro "logging.logging.error" local msg msg="$(logging.error Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;196m[ ERROR ] Cookie [0m" || fail "Message was wrong format $msg" + [[ "$msg" =~ \[38\;5\;196m\[\ ERROR\ \].*Cookie ]] || fail "Message was wrong format $msg" success } @@ -84,7 +84,7 @@ function logging.logging.warning { logging.set_level "$(logging.level.warning)" msg="$(logging.warning Cookie | tr -d -C '[:print:]')" - test "$msg" = "[93m[ WARNING ] Cookie [0m" || fail "Message was wrong format $msg" + [[ "$msg" =~ \[93m\[\ WARNING\ \].*Cookie ]] || fail "Message was wrong format $msg" success unset CRUCIBLE_LOGGING_LEVEL } @@ -93,7 +93,7 @@ function logging.logging.success { intro "logging.logging.success" local msg msg="$(logging.success Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;82m[ SUCCESS ] Cookie [0m" || fail "Message was wrong format $msg" + [[ "$msg" =~ \[38\;5\;82m\[\ SUCCESS\ \].*Cookie ]] || fail "Message was wrong format $msg" success } @@ -101,7 +101,7 @@ function logging.logging.message { intro "logging.logging.message" local msg msg="$(logging.message Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;86m[ INFO ] Cookie [0m" || fail "Message was wrong format $msg" + [[ "$msg" =~ \[38\;5\;86m\[\ INFO\ \].*Cookie ]] || fail "Message was wrong format $msg" success } @@ -109,7 +109,7 @@ function logging.logging.log { intro "logging.logging.log" local msg msg="$(logging.log Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;86m[ INFO ] Cookie [0m" || fail "Message was wrong format $msg" + [[ "$msg" =~ \[38\;5\;86m\[\ INFO\ \].*Cookie ]] || fail "Message was wrong format $msg" success } From 1b0f32ec717287df5980ea037b5573273dac0a1b Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 21 Feb 2020 12:31:06 +0100 Subject: [PATCH 5/9] Fixed tests for logging/logging as it uses dates --- test/bash/logging/logging.sh | 75 +++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/test/bash/logging/logging.sh b/test/bash/logging/logging.sh index 8bb22b3..117c791 100644 --- a/test/bash/logging/logging.sh +++ b/test/bash/logging/logging.sh @@ -51,8 +51,15 @@ function logging.logging.info { intro "logging.logging.info" local msg msg="$(logging.info Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;86m[ INFO ] Cookie [0m" || fail "Message was wrong format $msg" - success + pattern="\\[38;5;86m\\[ INFO \\] .* Cookie \\[0m" + + if [[ "$msg" =~ $pattern ]] + then + success + else + fail "Message was wrong format $msg" + fi + } function logging.logging.debug { @@ -63,8 +70,15 @@ function logging.logging.debug { logging.set_level "$(logging.level.debug)" msg="$(logging.debug Cookie | tr -d -C '[:print:]')" - test "$msg" = "[34m[ DEBUG ] Cookie [0m" || fail "Message was wrong format $msg" - success + pattern="\\[34m\\[ DEBUG \\] .* Cookie \\[0m" + + if [[ "$msg" =~ $pattern ]] + then + success + else + fail "Message was wrong format $msg" + fi + unset CRUCIBLE_LOGGING_LEVEL } @@ -72,8 +86,14 @@ function logging.logging.error { intro "logging.logging.error" local msg msg="$(logging.error Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;196m[ ERROR ] Cookie [0m" || fail "Message was wrong format $msg" - success + pattern="\\[38;5;196m\\[ ERROR \\] .* Cookie \\[0m" + + if [[ "$msg" =~ $pattern ]] + then + success + else + fail "Message was wrong format $msg" + fi } function logging.logging.warning { @@ -84,8 +104,15 @@ function logging.logging.warning { logging.set_level "$(logging.level.warning)" msg="$(logging.warning Cookie | tr -d -C '[:print:]')" - test "$msg" = "[93m[ WARNING ] Cookie [0m" || fail "Message was wrong format $msg" - success + pattern="\\[93m\\[ WARNING \\] .* Cookie \\[0m" + + if [[ "$msg" =~ $pattern ]] + then + success + else + fail "Message was wrong format $msg" + fi + unset CRUCIBLE_LOGGING_LEVEL } @@ -93,24 +120,44 @@ function logging.logging.success { intro "logging.logging.success" local msg msg="$(logging.success Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;82m[ SUCCESS ] Cookie [0m" || fail "Message was wrong format $msg" - success + pattern="\\[38;5;82m\\[ SUCCESS \\] .* Cookie \\[0m" + + if [[ "$msg" =~ $pattern ]] + then + success + else + fail "Message was wrong format $msg" + fi + } function logging.logging.message { intro "logging.logging.message" local msg msg="$(logging.message Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;86m[ INFO ] Cookie [0m" || fail "Message was wrong format $msg" - success + pattern="\\[38;5;86m\\[ INFO \\] .* Cookie \\[0m" + + if [[ "$msg" =~ $pattern ]] + then + success + else + fail "Message was wrong format $msg" + fi + } function logging.logging.log { intro "logging.logging.log" local msg msg="$(logging.log Cookie | tr -d -C '[:print:]')" - test "$msg" = "[38;5;86m[ INFO ] Cookie [0m" || fail "Message was wrong format $msg" - success + pattern="\\[38;5;86m\\[ INFO \\] .* Cookie \\[0m" + + if [[ "$msg" =~ $pattern ]] + then + success + else + fail "Message was wrong format $msg" + fi } echo "Testing logging/logging" From 1a2f582a9ec5d0292267e78811342a6a5c8aa87a Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 21 Feb 2020 12:50:46 +0100 Subject: [PATCH 6/9] Added dates tests and fixed typo in function name --- src/bash/dates/utc.sh | 2 +- test/bash/dates/utc.sh | 143 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 test/bash/dates/utc.sh diff --git a/src/bash/dates/utc.sh b/src/bash/dates/utc.sh index a2f9f3a..3511141 100644 --- a/src/bash/dates/utc.sh +++ b/src/bash/dates/utc.sh @@ -69,7 +69,7 @@ function dates.utc.iso8601.ns { fi } -function dates.utc.is8601.seconds { +function dates.utc.iso8601.seconds { if [ -z "$1" ] then date -u --iso-8601=seconds diff --git a/test/bash/dates/utc.sh b/test/bash/dates/utc.sh new file mode 100644 index 0000000..b46e4a2 --- /dev/null +++ b/test/bash/dates/utc.sh @@ -0,0 +1,143 @@ +#!/usr/bin/env bash +# shellcheck disable=SC1090 +source "$(dirname "$0")/../../.utils" +mkdir tmp/dates/utc -p +cd tmp/dates/utc || fail "Could not change dir" +setup +# shellcheck disable=SC1091 +source .mould + +require dates/utc + +declare -a tests + +tests=("dates.dates.utc.now") +tests+=("dates.dates.utc.now.timestamp") +tests+=("dates.dates.utc.rfc3339.ns") +tests+=("dates.dates.utc.rfc3339.seconds") +tests+=("dates.dates.utc.rfc3339.date") +tests+=("dates.dates.utc.email") +tests+=("dates.dates.utc.iso8601.ns") +tests+=("dates.dates.utc.iso8601.seconds") +tests+=("dates.dates.utc.iso8601.minutes") +tests+=("dates.dates.utc.iso8601.hours") +tests+=("dates.dates.utc.iso8601.date") + +function dates.dates.utc.now { + intro "dates.dates.utc.now" + + + date=$(dates.utc.now --date='@0') + test "$date" = "Thu Jan 1 00:00:00 UTC 1970" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.now.timestamp { + intro "dates.dates.utc.now.timestamp" + + + date=$(dates.utc.now.timestamp --date='@0') + test "$date" = "0" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.rfc3339.ns { + intro "dates.dates.utc.rfc3339.ns" + + + date=$(dates.utc.rfc3339.ns --date='@0') + test "$date" = "1970-01-01 00:00:00.000000000+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.rfc3339.seconds { + intro "dates.dates.utc.rfc3339.seconds" + + + date=$(dates.utc.rfc3339.seconds --date='@0') + test "$date" = "1970-01-01 00:00:00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.rfc3339.date { + intro "dates.dates.utc.rfc3339.date" + + + date=$(dates.utc.rfc3339.date --date='@0') + test "$date" = "1970-01-01" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.email { + intro "dates.dates.utc.email" + + + date=$(dates.utc.email --date='@0') + test "$date" = "Thu, 01 Jan 1970 00:00:00 +0000" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.iso8601.ns { + intro "dates.dates.utc.iso8601.ns" + + + date=$(dates.utc.iso8601.ns --date='@0') + test "$date" = "1970-01-01T00:00:00,000000000+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.iso8601.seconds { + intro "dates.dates.utc.iso8601.seconds" + + + date=$(dates.utc.iso8601.seconds --date='@0') + test "$date" = "1970-01-01T00:00:00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.iso8601.minutes { + intro "dates.dates.utc.iso8601.minutes" + + + date=$(dates.utc.iso8601.minutes --date='@0') + test "$date" = "1970-01-01T00:00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.iso8601.hours { + intro "dates.dates.utc.iso8601.hours" + + + date=$(dates.utc.iso8601.hours --date='@0') + test "$date" = "1970-01-01T00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.utc.iso8601.date { + intro "dates.dates.utc.iso8601.date" + + + date=$(dates.utc.iso8601.date --date='@0') + test "$date" = "1970-01-01" || fail "Date returned did not contain correct format: $date" + + success +} + +echo "Testing dates/utc" + +for test in "${tests[@]}" +do + "$test" +done + +teardown \ No newline at end of file From 1ae7b60d67bfad1baccf74c30bfdbd62f31e8e51 Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 21 Feb 2020 12:54:23 +0100 Subject: [PATCH 7/9] Added dates tests and fixed typo in function name for local --- src/bash/dates/local.sh | 2 +- test/bash/dates/local.sh | 143 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 test/bash/dates/local.sh diff --git a/src/bash/dates/local.sh b/src/bash/dates/local.sh index ecda6db..c971a53 100644 --- a/src/bash/dates/local.sh +++ b/src/bash/dates/local.sh @@ -75,7 +75,7 @@ function dates.local.iso8601.ns { } -function dates.local.is8601.seconds { +function dates.local.iso8601.seconds { if [ -z "$1" ] then date --iso-8601=seconds diff --git a/test/bash/dates/local.sh b/test/bash/dates/local.sh new file mode 100644 index 0000000..7e522f5 --- /dev/null +++ b/test/bash/dates/local.sh @@ -0,0 +1,143 @@ +#!/usr/bin/env bash +# shellcheck disable=SC1090 +source "$(dirname "$0")/../../.utils" +mkdir tmp/dates/local -p +cd tmp/dates/local || fail "Could not change dir" +setup +# shellcheck disable=SC1091 +source .mould + +require dates/local + +declare -a tests + +tests=("dates.dates.local.now") +tests+=("dates.dates.local.now.timestamp") +tests+=("dates.dates.local.rfc3339.ns") +tests+=("dates.dates.local.rfc3339.seconds") +tests+=("dates.dates.local.rfc3339.date") +tests+=("dates.dates.local.email") +tests+=("dates.dates.local.iso8601.ns") +tests+=("dates.dates.local.iso8601.seconds") +tests+=("dates.dates.local.iso8601.minutes") +tests+=("dates.dates.local.iso8601.hours") +tests+=("dates.dates.local.iso8601.date") + +function dates.dates.local.now { + intro "dates.dates.local.now" + + + date=$(dates.local.now --date='@0') + test "$date" = "Thu Jan 1 00:00:00 UTC 1970" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.now.timestamp { + intro "dates.dates.local.now.timestamp" + + + date=$(dates.local.now.timestamp --date='@0') + test "$date" = "0" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.rfc3339.ns { + intro "dates.dates.local.rfc3339.ns" + + + date=$(dates.local.rfc3339.ns --date='@0') + test "$date" = "1970-01-01 00:00:00.000000000+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.rfc3339.seconds { + intro "dates.dates.local.rfc3339.seconds" + + + date=$(dates.local.rfc3339.seconds --date='@0') + test "$date" = "1970-01-01 00:00:00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.rfc3339.date { + intro "dates.dates.local.rfc3339.date" + + + date=$(dates.local.rfc3339.date --date='@0') + test "$date" = "1970-01-01" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.email { + intro "dates.dates.local.email" + + + date=$(dates.local.email --date='@0') + test "$date" = "Thu, 01 Jan 1970 00:00:00 +0000" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.iso8601.ns { + intro "dates.dates.local.iso8601.ns" + + + date=$(dates.local.iso8601.ns --date='@0') + test "$date" = "1970-01-01T00:00:00,000000000+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.iso8601.seconds { + intro "dates.dates.local.iso8601.seconds" + + + date=$(dates.local.iso8601.seconds --date='@0') + test "$date" = "1970-01-01T00:00:00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.iso8601.minutes { + intro "dates.dates.local.iso8601.minutes" + + + date=$(dates.local.iso8601.minutes --date='@0') + test "$date" = "1970-01-01T00:00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.iso8601.hours { + intro "dates.dates.local.iso8601.hours" + + + date=$(dates.local.iso8601.hours --date='@0') + test "$date" = "1970-01-01T00+00:00" || fail "Date returned did not contain correct format: $date" + + success +} + +function dates.dates.local.iso8601.date { + intro "dates.dates.local.iso8601.date" + + + date=$(dates.local.iso8601.date --date='@0') + test "$date" = "1970-01-01" || fail "Date returned did not contain correct format: $date" + + success +} + +echo "Testing dates/local" + +for test in "${tests[@]}" +do + "$test" +done + +teardown \ No newline at end of file From f0c625fd92ced370b000f3b3fb0a59087d686167 Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 21 Feb 2020 12:57:22 +0100 Subject: [PATCH 8/9] Updated README.md with roadmap --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30c807a..9ee661d 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,12 @@ By running the following command you get a nice clean environment in which `cruc ## Core -- [ ] Dates +- [X] Dates - [X] Logging - [X] Arrays +- [ ] File I/O +- [ ] Network I/O +- [ ] Processes # Static Code Analysis From d673abda2e0b1683db91d571ded4c46a6cb2bb82 Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Fri, 21 Feb 2020 13:00:57 +0100 Subject: [PATCH 9/9] Bumped version to 0.2.2 --- src/bash/arrays/arrays.sh | 4 ++-- src/bash/bin/crucible | 4 ++-- src/bash/core/.internal.sh | 4 ++-- src/bash/core/dummy.sh | 4 ++-- src/bash/core/mould.sh | 4 ++-- src/bash/dates/dates.sh | 4 ++-- src/bash/dates/local.sh | 4 ++-- src/bash/dates/utc.sh | 4 ++-- src/bash/logging/.constants.sh | 4 ++-- src/bash/logging/.internal.sh | 4 ++-- src/bash/logging/logging.sh | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/bash/arrays/arrays.sh b/src/bash/arrays/arrays.sh index df5dc19..f2c03a8 100644 --- a/src/bash/arrays/arrays.sh +++ b/src/bash/arrays/arrays.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### require core/.internal diff --git a/src/bash/bin/crucible b/src/bash/bin/crucible index ff23c14..26302ef 100755 --- a/src/bash/bin/crucible +++ b/src/bash/bin/crucible @@ -1,6 +1,6 @@ #!/usr/bin/env bash -CRUCIBLE_VERSION=0.2.1 -CRUCIBLE_LOCATION=${CRUCIBLE_LOCATION:-develop} +CRUCIBLE_VERSION=0.2.2 +CRUCIBLE_LOCATION=v0.2.2 function get_uuid { grep 'id' .crucible | cut -d'=' -f 2 diff --git a/src/bash/core/.internal.sh b/src/bash/core/.internal.sh index 3477666..311f373 100644 --- a/src/bash/core/.internal.sh +++ b/src/bash/core/.internal.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### require logging/logging diff --git a/src/bash/core/dummy.sh b/src/bash/core/dummy.sh index 348c3db..c751e7e 100644 --- a/src/bash/core/dummy.sh +++ b/src/bash/core/dummy.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### function noop { diff --git a/src/bash/core/mould.sh b/src/bash/core/mould.sh index 92ed9e0..7c0a759 100644 --- a/src/bash/core/mould.sh +++ b/src/bash/core/mould.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### function require { diff --git a/src/bash/dates/dates.sh b/src/bash/dates/dates.sh index 2c13fd2..1f085bb 100644 --- a/src/bash/dates/dates.sh +++ b/src/bash/dates/dates.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### require dates/utc diff --git a/src/bash/dates/local.sh b/src/bash/dates/local.sh index c971a53..05e554d 100644 --- a/src/bash/dates/local.sh +++ b/src/bash/dates/local.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### function dates.local.now { diff --git a/src/bash/dates/utc.sh b/src/bash/dates/utc.sh index 3511141..a61ddb6 100644 --- a/src/bash/dates/utc.sh +++ b/src/bash/dates/utc.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### function dates.utc.now { diff --git a/src/bash/logging/.constants.sh b/src/bash/logging/.constants.sh index 8c06458..3eb20f1 100644 --- a/src/bash/logging/.constants.sh +++ b/src/bash/logging/.constants.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### function logging.color.escape_char { diff --git a/src/bash/logging/.internal.sh b/src/bash/logging/.internal.sh index b0c3918..541ac41 100644 --- a/src/bash/logging/.internal.sh +++ b/src/bash/logging/.internal.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### require logging/.constants diff --git a/src/bash/logging/logging.sh b/src/bash/logging/logging.sh index aefd8c9..5f6a960 100644 --- a/src/bash/logging/logging.sh +++ b/src/bash/logging/logging.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash ### CRUCIBLE META DATA ### -# CRUCIBLE_VERSION={CRUCIBLE_VERSION} +# CRUCIBLE_VERSION=0.2.2 # CRUCIBLE_AUTHOR=StealthyCoder -# CRUCIBLE_CREATED={CRUCIBLE_CREATED} +# CRUCIBLE_CREATED=1582286436 ### CRUCIBLE META DATA ### require logging/.internal