Skip to content

Commit

Permalink
add (user mode testing): add a beginning of a simple bash unit tester…
Browse files Browse the repository at this point in the history
… for the shell_commands script and it's functions
  • Loading branch information
ekluzek committed Dec 1, 2024
1 parent 4686632 commit 8f72cd6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

User mod directory to make sure the user is setup to run the FATES modify param file script.
IF not it trys some different options and prints messages regarding what worked, and what the user
needs to do if nothing worked.



Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Define a custom error handler function
handle_error() {
echo "An error occurred: $1"
echo "error code: $?"
# Additional error handling code can go here
return 1
}

# Set the error handler to be called when an error occurs
trap 'handle_error "Something went wrong!"' ERR

host=`hostname -f`
if [[ "$host" =~ derecho*.hpc.ucar.edu || "$host" =~ d*.hpc.ucar.edu ]] ; then
echo "Running on Derecho..." >&2
echo ".... making sure conda is loaded..." >&2
module load conda
else
echo "Not a recognized host: $host" >&2
exit 5
fi
echo "Test if shell_commands will run..."
. ./shell_commands > /dev/null

echo "Now do some tests of the bash subroutines" >&2
unset DEBUG
$(log_msg_if_debug "Die with Error since DEBUG is unset")
if [[ "$?" -eq "0" ]]; then
echo "Should have died with an error..." >&2
exit 1
fi
echo "after DEBUG test"
DEBUG=0
$(log_msg_if_debug "Die with Error since too many options are input" "another option")

echo "Successful"

0 comments on commit 8f72cd6

Please sign in to comment.