]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
tests: add and use test_autoenv_add_to_env and test_autoenv_auth_env_files
authorDaniel Hahler <git@thequod.de>
Fri, 21 Nov 2014 22:07:53 +0000 (23:07 +0100)
committerDaniel Hahler <git@thequod.de>
Mon, 24 Nov 2014 19:13:18 +0000 (20:13 +0100)
Conflicts:
autoenv.zsh

autoenv.zsh
tests/autoenv.t
tests/cwd.t
tests/setup.sh
tests/varstash.t

index 5be6c315e3e2781a89f962b3145be620a0014f59..317217f43a048ac6870696cabb8b33b610a6e824 100644 (file)
@@ -24,6 +24,11 @@ _dotenv_stack_entered=()
 
 _dotenv_hash_pair() {
   local env_file=$1
+  if (( $+2 )); then
+    env_shasum=$2
+  else
+    env_shasum=$(shasum $env_file | cut -d' ' -f1)
+  fi
   echo "$env_file:$env_shasum:1"
 }
 
index 47509129e259bf31fd504573da2a28a02ef6277d..f477c1377ef9e0dd1b1068f1a06253c4012a1557 100644 (file)
@@ -6,7 +6,7 @@ Lets set a simple .env action
 
 Manually create auth file
 
-  $ echo "$PWD/.env:$(echo echo ENTERED | shasum)" > $AUTOENV_ENV_FILENAME
+  $ test_autoenv_add_to_env $PWD/.env
   $ cd .
   ENTERED
 
@@ -41,7 +41,7 @@ Now lets see that it actually checks the shasum value
 
   $ unset _dotenv_stack_entered
   $ rm $AUTOENV_ENV_FILENAME
-  $ echo "$PWD/.env:$(echo mischief | shasum)" > $AUTOENV_ENV_FILENAME
+  $ test_autoenv_add_to_env $PWD/.env mischief
   $ cd .
   Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob)
   
index 99f77fe45ebf81bdbd6b73bad0671836d9161fbb..2c5838a2be75a3f880c3b6c96db6b94157e7a19a 100644 (file)
@@ -12,8 +12,7 @@ Setup env actions / output.
 
 Manually create auth files.
 
-  $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $AUTOENV_ENV_FILENAME
-  $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME
+  $ test_autoenv_auth_env_files
 
 The actual tests.
 
index b2f5aafb12b1d749b524fb4b0526b90c61afff0b..a7da1b46b5d811485f8b404de959c2d4a58c59c8 100644 (file)
@@ -1,6 +1,18 @@
 # Ensure we have our mocked out AUTOENV_ENV_FILENAME
+# (via .zshenv).
 
 [[ $AUTOENV_ENV_FILENAME[0,4] == '/tmp' ]] || return 1
 
 # Inject timeout for `read` while running tests.
 _AUTOENV_TEST_READ_ARGS='-t 1'
+
+test_autoenv_add_to_env() {
+  _dotenv_hash_pair $1 $2 >> $AUTOENV_ENV_FILENAME
+}
+
+# Add enter and leave env files to authentication file.
+test_autoenv_auth_env_files() {
+  echo -n > $AUTOENV_ENV_FILENAME
+  test_autoenv_add_to_env $PWD/$DOTENV_FILE_ENTER
+  test_autoenv_add_to_env $PWD/$DOTENV_FILE_LEAVE
+}
index bc49657850347620803c106a05e6db09178f5d6c..c6d33f064ce7c82a7c34b1e395e69ebcdcf623ca 100644 (file)
@@ -16,8 +16,7 @@ Setup test environment.
 
 Manually create auth file
 
-  $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $AUTOENV_ENV_FILENAME
-  $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME
+  $ test_autoenv_auth_env_files
 
 Set environment variable.