Skip to content

Commit

Permalink
sh tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Oct 25, 2021
1 parent e0032bc commit 6d39e33
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
13 changes: 7 additions & 6 deletions bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ else
JAVA=${JAVA_HOME}/bin/java
fi

PROJECT_TARGET_DIR=${PROJECT_TARGET_DIR:-target}
BINDIR=${BK_BINDIR:-"`dirname "$0"`"}
BK_HOME=${BK_HOME:-"`cd ${BINDIR}/..;pwd`"}
BK_CONFDIR=${BK_HOME}/conf
Expand Down Expand Up @@ -196,7 +197,7 @@ find_module_jar() {
fi

if [ -z "${MODULE_JAR}" ]; then
BUILT_JAR=$(find_module_jar_at ${BK_HOME}/${MODULE_PATH}/target ${MODULE_NAME})
BUILT_JAR=$(find_module_jar_at ${BK_HOME}/${MODULE_PATH}/${PROJECT_TARGET_DIR} ${MODULE_NAME})
if [ -z "${BUILT_JAR}" ]; then
echo "Couldn't find module '${MODULE_NAME}' jar." >&2
read -p "Do you want me to run \`mvn package -DskipTests\` for you ? (y|n) " answer
Expand All @@ -212,7 +213,7 @@ find_module_jar() {
;;
esac

BUILT_JAR=$(find_module_jar_at ${BK_HOME}/${MODULE_PATH}/target ${MODULE_NAME})
BUILT_JAR=$(find_module_jar_at ${BK_HOME}/${MODULE_PATH}/${PROJECT_TARGET_DIR} ${MODULE_NAME})
fi
if [ -n "${BUILT_JAR}" ]; then
MODULE_JAR=${BUILT_JAR}
Expand All @@ -237,12 +238,12 @@ add_maven_deps_to_classpath() {
# Need to generate classpath from maven pom. This is costly so generate it
# and cache it. Save the file into our target dir so a mvn clean will get
# clean it up and force us create a new one.
f="${BK_HOME}/${MODULE_PATH}/target/cached_classpath.txt"
output="${BK_HOME}/${MODULE_PATH}/target/build_classpath.out"
f="${BK_HOME}/${MODULE_PATH}/${PROJECT_TARGET_DIR}/cached_classpath.txt"
output="${BK_HOME}/${MODULE_PATH}/${PROJECT_TARGET_DIR}/build_classpath.out"
if [ ! -f ${f} ]; then
echo "the classpath of module '${MODULE_PATH}' is not found, generating it ..." >&2
echo "see output at ${output} for the progress ..." >&2
${MVN} -f "${BK_HOME}/${MODULE_PATH}/pom.xml" dependency:build-classpath -Dmdep.outputFile="target/cached_classpath.txt" &> ${output}
${MVN} -f "${BK_HOME}/${MODULE_PATH}/pom.xml" dependency:build-classpath -Dmdep.outputFile="${PROJECT_TARGET_DIR}/cached_classpath.txt" &> ${output}
echo "the classpath of module '${MODULE_PATH}' is generated at '${f}'." >&2
fi
}
Expand All @@ -257,7 +258,7 @@ set_module_classpath() {
echo ${BK_CLASSPATH}
else
add_maven_deps_to_classpath ${MODULE_PATH} >&2
cat ${BK_HOME}/${MODULE_PATH}/target/cached_classpath.txt
cat ${BK_HOME}/${MODULE_PATH}/${PROJECT_TARGET_DIR}/cached_classpath.txt
fi
return
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ include(':bookkeeper-benchmark',
'tests:integration:cluster',
'tests:integration:smoke',
'tests:integration:standalone',
'tests:scripts',
'tools:framework')

project(':bookkeeper-tools').projectDir = file('tools/all')
Expand Down
43 changes: 43 additions & 0 deletions tests/scripts/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/


plugins {
id "de.undercouch.download" version "4.1.2"
}



task downloadShunit2(type: Download) {
src 'https://github.com/kward/shunit2/archive/v2.1.7.zip'
dest new File(buildDir, "shunit2-2.1.7.zip")
}

task extractShunit2(dependsOn: downloadShunit2, type: Copy) {
from zipTree(downloadShunit2.dest)
into new File(buildDir, "lib")
}

task executeShTests(dependsOn: extractShunit2, type: Exec) {

workingDir "src/test/bash"
commandLine "./bk_test.sh"
args "build"
}
tasks.test.dependsOn("executeShTests")
3 changes: 3 additions & 0 deletions tests/scripts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<skip>${skipTests}</skip>
<workingDirectory>${project.basedir}/src/test/bash</workingDirectory>
<executable>${project.basedir}/src/test/bash/bk_test.sh</executable>
<arguments>
<argument>target</argument>
</arguments>
</configuration>
</execution>
</executions>
Expand Down
1 change: 1 addition & 0 deletions tests/scripts/src/test/bash/bk_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# */

ARGV0=`basename "$0"`
export PROJECT_TARGET_DIR="build"
PREFIX="bk_test_"
SHELLS="/bin/sh /bin/bash"

Expand Down
6 changes: 3 additions & 3 deletions tests/scripts/src/test/bash/bk_test_bin_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ testFindModuleJar() {
TEST_FILES=(
"${MODULE}-${VERSION}.jar"
"lib/${MODULE}-${VERSION}.jar"
"${MODULE_PATH}/target/${MODULE}-${VERSION}.jar"
"${MODULE_PATH}/${PROJECT_TARGET_DIR}/${MODULE}-${VERSION}.jar"
)
count=0
while [ "x${TEST_FILES[count]}" != "x" ]
Expand Down Expand Up @@ -187,8 +187,8 @@ testSetModuleClasspath() {

MODULE_PATH="testmodule"

mkdir -p ${BK_HOME}/${MODULE_PATH}/target
echo "test-classpath" > ${BK_HOME}/${MODULE_PATH}/target/cached_classpath.txt
mkdir -p ${BK_HOME}/${MODULE_PATH}/${PROJECT_TARGET_DIR}
echo "test-classpath" > ${BK_HOME}/${MODULE_PATH}/${PROJECT_TARGET_DIR}/cached_classpath.txt

local result=$(set_module_classpath ${MODULE_PATH})
assertEquals "test-classpath" ${result}
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/src/test/bash/bk_test_helpers
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
BK_ARGV0=`basename "$0"`

# path to shUnit2 library. can be overridden by setting BK_SHUNIT_INC.
BK_SHUNIT=${BK_SHUNIT_INC:-../../../target/lib/shunit2-2.1.7/shunit2}
BK_SHUNIT=${BK_SHUNIT_INC:-../../../${PROJECT_TARGET_DIR}/lib/shunit2-2.1.7/shunit2}

# path to bk bin directory.
TESTDIR=`dirname "$0"`
Expand Down

0 comments on commit 6d39e33

Please sign in to comment.