Skip to content

Commit

Permalink
Use a better algorithm in function absolute_path
Browse files Browse the repository at this point in the history
For function absolute_path in commonFunctionsForTests.sh, we now
use a better algorithm.  If the path exists, we use readlink -f
to get the absolute path.  Otherwise we just replace ~ with $HOME.
This avoids issues with paths that don't exist.

In the intTestCreate.sh scripts, we make sure to call absolute_path
for the root directory again after the root folder is made.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
  • Loading branch information
yantosca committed Nov 20, 2020
1 parent 4551d18 commit b131c21
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions test/GCClassic/intTestCreate.sh
Expand Up @@ -95,6 +95,10 @@ if [[ ! -d ${root} ]]; then
mkdir -p ${root}
fi

# Get the absolute path of the root folder again;
# now that the folder exists
root=$(absolute_path ${root})

# Remove everything in the test folde r
cleanup_files ${root}

Expand Down Expand Up @@ -137,6 +141,13 @@ cd ${runDir}
# Create individual run directories: 2x25 - MERRA2 - 72L
#=============================================================================

if [[ -d ${root} ]]; then
extra="y\n"
else
extra=""
fi
echo ${extra}

dir="gc_2x25_CH4_merra2"
create_rundir "3\n1\n2\n1\n${root}\n${dir}\nn\n" ${root} ${dir} ${log}

Expand Down
4 changes: 4 additions & 0 deletions test/GCHPctm/intTestCreate.sh
Expand Up @@ -94,6 +94,10 @@ if [[ ! -d ${root} ]]; then
mkdir -p ${root}
fi

# Get the absolute path of the root folder again;
# now that the folder exists
root=$(absolute_path ${root})

# Remove run directories in the test folder
cleanup_files ${root}

Expand Down
7 changes: 6 additions & 1 deletion test/shared/commonFunctionsForTests.sh
Expand Up @@ -46,7 +46,12 @@ function absolute_path() {
#
# 1st argument = relative path
#========================================================================
printf "$(cd "$(dirname "${1}")"; pwd -P)/$(basename "${1}")"
if [[ -d ${1} ]]; then
absPath=$(readlink -f "${1}") # If directory exists, use readlink
else
absPath="${1/#\~/$HOME}" # Otherwise, replace ~ with $HOME
fi
echo "${absPath}"
}


Expand Down

0 comments on commit b131c21

Please sign in to comment.