Skip to content

Commit

Permalink
Run ww_activate script on linux workspace activation
Browse files Browse the repository at this point in the history
On Linux, this script was already being created for this purpose, but it was not
being executed. On Windows it was working correctly.
  • Loading branch information
lvoliveira committed Jan 17, 2024
1 parent f62eec8 commit 2858fcf
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 33 deletions.
57 changes: 24 additions & 33 deletions test_ww
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
#!/bin/bash

assert_equal() {
if [ $1 != $2 ]; then
errorOut "Assertion failed: $1 is not equal to $2'"
fi
}
# load test tools
. ./testing/test_tools

test_can_activate_workspace() {
echo ""
echo "Testing ${FUNCNAME[0]}"
echo ""

local test_dir=$(pwd)

mkdir $test_dir/temp-ww-workdir
export WW_DEFAULT_PATH=$test_dir/temp-ww-workdir

# create and activate workspace 'ws1'
$test_dir/ww -c ws1
source ./ww ws1

# check that the correct workspace was activated
assert_equal $WW_CURRENT_WORKSPACE ws1
assert_equal $CONDA_ENVS_PATH $test_dir/temp-ww-workdir/ws1/envs

cd $test_dir
rm -rf temp-ww-workdir
}


test_can_activate_current() {
echo ""
echo "Testing ${FUNCNAME[0]}"
echo ""
local test_dir=$(pwd)

mkdir $test_dir/temp-ww-workdir
export WW_DEFAULT_PATH=$test_dir/temp-ww-workdir

test_can_activate_current() {
$test_dir/ww -c ws2

cd ./temp-ww-workdir/ws2/Projects
cd $WW_DEFAULT_PATH/ws2/Projects

local cwd_before=$(pwd)
source $test_dir/ww .
Expand All @@ -51,12 +28,26 @@ test_can_activate_current() {
# check that the correct workspace was activated
assert_equal $WW_CURRENT_WORKSPACE ws2
assert_equal $CONDA_ENVS_PATH $test_dir/temp-ww-workdir/ws2/envs
}

cd $test_dir
rm -rf temp-ww-workdir
test_ww_activate_script_is_called() {
$test_dir/ww -c ws1

echo "export TEMP_TEST_VAR=1" >> $WW_DEFAULT_PATH/ws1/ww_activate.sh

source ./ww ws1

# check that the correct workspace was activated
assert_equal $WW_CURRENT_WORKSPACE ws1
assert_equal $TEMP_TEST_VAR 1
}

echo "Testing file test_ww"
test_can_activate_workspace
test_can_activate_current
echo "Success"
echo ""

test "test_can_activate_workspace"
test "test_can_activate_current"
test "test_ww_activate_script_is_called"

echo ""
printGreen "Success"
62 changes: 62 additions & 0 deletions testing/test_tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
test() {
local test_function=$1

echo -n "Testing ${test_function} ... "

setup

# run test function
output=$($test_function)
failed=$?

tier_down

if [ $failed != 0 ]; then
printRed "Failed"
echo ""
echo "------------ Test Output ------------"
echo "$test_function:"
echo "$output"
exit 1
fi

printGreen "Success"
}

setup() {
test_dir=$(pwd)

rm -rf temp-ww-workdir
mkdir $test_dir/temp-ww-workdir
export WW_DEFAULT_PATH=$test_dir/temp-ww-workdir
}

tier_down() {
cd $test_dir
rm -rf temp-ww-workdir
}

assert_equal() {
if [ $1 != $2 ]; then
testErrorOut "Assertion failed: $1 is not equal to $2'"
fi
}

testErrorOut() {
printRed "ERROR: $@"
exit 1
}

printGreen() {
green=`tput setaf 2`
reset=`tput sgr0`
echo "${green}$1${reset}"
}

printRed() {
red=`tput setaf 1`
reset=`tput sgr0`
echo "${red}$1${reset}"
}

6 changes: 6 additions & 0 deletions ww
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ activate() {
if [[ -n $WW_CONDA_PKGS_PATH ]]; then
export CONDA_PKGS_PATH=$WW_CONDA_PKGS_PATH
fi

# Run ww_activate.sh script if one exists
ACTIVATE_SCRIPT="${workspace}/ww_activate.sh"
if [ -f "$ACTIVATE_SCRIPT" ]; then
. "$ACTIVATE_SCRIPT"
fi
}

activate_current() {
Expand Down

0 comments on commit 2858fcf

Please sign in to comment.