Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/run-tests.sh
3544 views
1
#!/usr/bin/env bash
2
3
# Determine the path to this script (we'll use this to figure out relative positions of other files)
4
SOURCE="${BASH_SOURCE[0]}"
5
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
6
SCRIPT_PATH="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
7
SOURCE="$(readlink "$SOURCE")"
8
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
9
done
10
export SCRIPT_PATH="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
11
12
source $SCRIPT_PATH/../package/scripts/common/utils.sh
13
14
export QUARTO_ROOT="`cd "$SCRIPT_PATH/.." > /dev/null 2>&1 && pwd`"
15
QUARTO_SRC_DIR="$QUARTO_ROOT/src"
16
DENO_ARCH_DIR=$DENO_DIR
17
DENO_DIR="$QUARTO_ROOT/package/dist/bin/"
18
19
# Local import map
20
QUARTO_IMPORT_MAP_ARG=--importmap=$QUARTO_SRC_DIR/import_map.json
21
22
export QUARTO_BIN_PATH=$DENO_DIR
23
export QUARTO_SHARE_PATH="`cd "$QUARTO_ROOT/src/resources/";pwd`"
24
export QUARTO_DEBUG=true
25
26
QUARTO_DENO_OPTIONS="--config test-conf.json --v8-flags=--enable-experimental-regexp-engine,--max-old-space-size=8192,--max-heap-size=8192 --unstable-kv --unstable-ffi --no-lock --allow-all"
27
28
29
if [[ -z $GITHUB_ACTION ]] && [[ -z $QUARTO_TESTS_NO_CONFIG ]]
30
then
31
echo "> Checking and configuring environment for tests"
32
source configure-test-env.sh
33
fi
34
35
# Activating python virtualenv
36
# set QUARTO_TESTS_FORCE_NO_VENV env var to not activate the virtualenv located in the project
37
# QUARTO_TESTS_FORCE_NO_PIPENV is there for backward compatibility
38
if [[ -z $QUARTO_TESTS_FORCE_NO_VENV && -n $QUARTO_TESTS_FORCE_NO_PIPENV ]]; then
39
export QUARTO_TESTS_FORCE_NO_VENV=$QUARTO_TESTS_FORCE_NO_PIPENV
40
fi
41
if [[ -z $QUARTO_TESTS_FORCE_NO_VENV ]]
42
then
43
# Save possible activated virtualenv for later restauration
44
OLD_VIRTUAL_ENV=$VIRTUAL_ENV
45
echo "> Activating virtualenv from .venv for Python tests in Quarto"
46
source "${QUARTO_ROOT}/tests/.venv/bin/activate"
47
echo "> Using Python from $(which python)"
48
echo "> VIRTUAL_ENV: ${VIRTUAL_ENV}"
49
quarto_venv_activated="true"
50
fi
51
52
SMOKE_ALL_TEST_FILE="./smoke/smoke-all.test.ts"
53
54
# RUN FOR TIMING TESTS ONLY
55
if [ "$QUARTO_TEST_TIMING" != "" ] && [ "$QUARTO_TEST_TIMING" != "false" ]; then
56
if [ "$QUARTO_TEST_TIMING" == "true" ]; then
57
QUARTO_TEST_TIMING="timing.txt"
58
fi
59
echo "> Running tests with timing and writing to ${QUARTO_TEST_TIMING}"
60
rm -f $QUARTO_TEST_TIMING
61
FILES=$@
62
if [ "$FILES" == "" ]; then
63
FILES=`find . | grep \.test\.ts$ | sort`
64
fi
65
for i in $FILES; do
66
if [ "$i" == "./test.ts" ]; then
67
# ignoring this file as this is not a test file to time
68
continue
69
fi
70
# For smoke-all.test.ts, each smoke-all document test needs to be timed.
71
if [ "$i" == "$SMOKE_ALL_TEST_FILE" ]; then
72
echo "> Timing smoke-all tests"
73
SMOKE_ALL_FILES=`find docs/smoke-all/ -type f -regextype "posix-extended" -regex ".*/[^_][^/]*[.]qmd" -o -regex ".*/[^_][^/]*[.]md" -o -regex ".*/[^_][^/]*[.]ipynb"`
74
for j in $SMOKE_ALL_FILES; do
75
echo "${SMOKE_ALL_TEST_FILE} -- ${j}" >> "$QUARTO_TEST_TIMING"
76
/usr/bin/time -f " %e real %U user %S sys" -a -o ${QUARTO_TEST_TIMING} "${DENO_DIR}/tools/${DENO_ARCH_DIR}/deno" test ${QUARTO_DENO_OPTIONS} --no-check ${QUARTO_DENO_EXTRA_OPTIONS} "${QUARTO_IMPORT_MAP_ARG}" ${SMOKE_ALL_TEST_FILE} -- ${j}
77
done
78
continue
79
fi
80
# Otherwise we time the individual test.ts test
81
echo $i >> "$QUARTO_TEST_TIMING"
82
/usr/bin/time -f " %e real %U user %S sys" -a -o "$QUARTO_TEST_TIMING" "${DENO_DIR}/tools/${DENO_ARCH_DIR}/deno" test ${QUARTO_DENO_OPTIONS} --no-check ${QUARTO_DENO_EXTRA_OPTIONS} "${QUARTO_IMPORT_MAP_ARG}" $i
83
done
84
# exit the script with an error code if the timing file shows error
85
grep -q 'Command exited with non-zero status' $QUARTO_TEST_TIMING && SUCCESS=1 || SUCCESS=0
86
else
87
# RUN WHEN NO TIMING (GENERIC CASE)
88
89
## Short version syntax to run smoke-all.test.ts
90
## Only use if different than ./run-test.sh ./smoke/smoke-all.test.ts
91
if [[ "$1" =~ smoke-all\.test\.ts ]]; then
92
TESTS_TO_RUN=$@
93
else
94
# Check file argument
95
SMOKE_ALL_FILES=""
96
TESTS_TO_RUN=""
97
if [[ ! -z "$*" ]]; then
98
for file in "$*"; do
99
echo $file
100
filename=$(basename "$file")
101
# smoke-all.test.ts works with .qmd, .md and .ipynb but will ignored file starting with _
102
if [[ $filename =~ ^[^_].*[.]qmd$ ]] || [[ $filename =~ ^[^_].*[.]ipynb$ ]] || [[ $filename =~ ^[^_].*[.]md$ ]]; then
103
SMOKE_ALL_FILES="${SMOKE_ALL_FILES} ${file}"
104
elif [[ $file =~ .*[.]ts$ ]]; then
105
TESTS_TO_RUN="${TESTS_TO_RUN} ${file}"
106
echo $TESTS_TO_RUN
107
else
108
echo "#### WARNING"
109
echo "Only .ts, or .qmd, .md and .ipynb passed to smoke-all.test.ts are accepted (file starting with _ are ignored)."
110
echo "####"
111
exit 1
112
fi
113
done
114
fi
115
if [ "$SMOKE_ALL_FILES" != "" ]; then
116
if [ "$TESTS_TO_RUN" != "" ]; then
117
echo "#### WARNING"
118
echo "When passing .qmd, .md and/or .ipynb, only ./smoke/smoke-all.test.ts will be run. Other tests files are ignored."
119
echo "Ignoring ${TESTS_TO_RUN}."
120
echo "####"
121
fi
122
TESTS_TO_RUN="${SMOKE_ALL_TEST_FILE} -- ${SMOKE_ALL_FILES}"
123
fi
124
fi
125
"${DENO_DIR}/tools/${DENO_ARCH_DIR}/deno" test ${QUARTO_DENO_OPTIONS} --check ${QUARTO_DENO_EXTRA_OPTIONS} "${QUARTO_IMPORT_MAP_ARG}" $TESTS_TO_RUN
126
SUCCESS=$?
127
fi
128
129
if [[ $quarto_venv_activated == "true" ]]
130
then
131
echo "> Exiting virtualenv activated for tests"
132
deactivate
133
echo "> Using Python from $(which python)"
134
echo "> VIRTUAL_ENV: ${VIRTUAL_ENV}"
135
unset quarto_venv_activated
136
fi
137
if [[ -n $OLD_VIRTUAL_ENV ]]
138
then
139
echo "> Reactivating original virtualenv"
140
source $OLD_VIRTUAL_ENV/bin/activate
141
echo "> Using Python from $(which python)"
142
echo "> VIRTUAL_ENV: ${VIRTUAL_ENV}"
143
unset OLD_VIRTUAL_ENV
144
fi
145
146
# Generates the coverage report
147
if [[ $@ == *"--coverage"* ]]; then
148
149
# read the coverage value from the command
150
[[ $@ =~ .*--coverage=(.+) ]] && export COV="${BASH_REMATCH[1]}"
151
152
echo Generating coverage report...
153
${DENO_DIR}/deno coverage --unstable-kv --unstable-ffi ${COV} --lcov > ${COV}.lcov
154
genhtml -o ${COV}/html ${COV}.lcov
155
open ${COV}/html/index.html
156
fi
157
158
exit ${SUCCESS}
159
160