From 45475ec77e0477adf6f6345c0a4e69763957c939 Mon Sep 17 00:00:00 2001 From: Alexandre-Silva Date: Thu, 21 Jul 2016 15:11:11 +0100 Subject: [PATCH] Add test for --source flag and pull request suggestions Add a demo/sourcing.vars file to be used by the associated demo script. Modified mo argument parsing so that --help and --source=file do not need to be the first arguments for mo. And can in fact appear after or in the middle of filenames. --- .gitignore | 1 - demo/sourcing | 5 ----- demo/sourcing.vars | 2 ++ mo | 37 +++++++++++++++++++++++++------------ tests/source.expected | 5 +++++ tests/source.sh | 17 +++++++++++++++++ tests/source.vars | 4 ++++ 7 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 demo/sourcing.vars create mode 100644 tests/source.expected create mode 100755 tests/source.sh create mode 100644 tests/source.vars diff --git a/.gitignore b/.gitignore index bf77c8f..5a1b4f1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ diagnostic.test tests/*.diff spec/ spec-runner/ -demo/sourcing.vars diff --git a/demo/sourcing b/demo/sourcing index 01cfb6a..f9dd47f 100755 --- a/demo/sourcing +++ b/demo/sourcing @@ -4,11 +4,6 @@ cd "$(dirname "$0")" # Go to the script's directory -cat <sourcing.vars -export NAME="Alex" -export ARRAY=( AAA BBB CCC ) -EOF - cat <&2 + exit 1 + fi + ;; + + *) # Every arg that is not a flag or a option should be a file + files+=("$arg") + ;; + esac + done fi - moGetContent moContent "$@" + moGetContent moContent "${files[@]}" moParse "$moContent" "" true ) diff --git a/tests/source.expected b/tests/source.expected new file mode 100644 index 0000000..a3050ef --- /dev/null +++ b/tests/source.expected @@ -0,0 +1,5 @@ +value +* 1 +* 2 +* 3 +AAA BBB diff --git a/tests/source.sh b/tests/source.sh new file mode 100755 index 0000000..806ea73 --- /dev/null +++ b/tests/source.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +cd "${0%/*}" +cat </dev/null 2>&1 +[[ "$?" -ne 1 ]] && echo "mo accepted a non existent file" diff --git a/tests/source.vars b/tests/source.vars new file mode 100644 index 0000000..58b50d3 --- /dev/null +++ b/tests/source.vars @@ -0,0 +1,4 @@ +export VAR=value +export ARR=(1 2 3) +declare -A ASSOC_ARR +export ASSOC_ARR=([a]=AAA [b]=BBB) \ No newline at end of file