Skip to content

Commit 3a9284c

Browse files
authored
Merge pull request #29 from jasonlyle88/cross-os-nolog
Improve ability to run on windows
2 parents 0fbcd21 + 29a196f commit 3a9284c

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

source/sqlclUnitTest.sh

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ function main() {
158158
printf -- '%s' "${testResultString}"
159159
} # getTestResultColorizedString
160160

161+
function convertToWindowsPath() {
162+
local originalUnixPath="$1"
163+
local unixPath="${originalUnixPath}"
164+
local windowsPath
165+
166+
# Convert drive letter
167+
if [[ "${unixPath:0:1}" == '/' ]]; then
168+
windowsPath="${unixPath:1:1}:\\"
169+
170+
unixPath="${unixPath:3}"
171+
fi
172+
173+
windowsPath="${windowsPath}$(printf -- '%s' "${unixPath}" | sed 's|/|\\|g')"
174+
175+
printf -- '%s\n' "${windowsPath}"
176+
} # convertToWindowsPath
177+
161178
function executeUnitTest() {
162179
local testType="$1"
163180
local testFile="$2"
@@ -174,6 +191,10 @@ function main() {
174191
local resultFile
175192
local logFile
176193
local wrapperFile
194+
local nologParam
195+
local testFileOS
196+
local testFilenameOS
197+
local testDirectoryOS
177198

178199
testDirectory="$(dirname "${testFile}")"
179200
testFilename="$(basename "${testFile}")"
@@ -182,6 +203,23 @@ function main() {
182203

183204
cd "${testDirectory}" || return 1
184205

206+
# Determine cross-os specific variables needed for execute
207+
if [[ "${OSTYPE}" == "cygwin" || "${OSTYPE}" == "msys" || "${OSTYPE}" == "win32" ]]; then
208+
# Handle Windows systems
209+
nologParam="//nolog"
210+
211+
testFileOS="$(convertToWindowsPath "${testFile}")"
212+
testDirectoryOS="$(convertToWindowsPath "${testDirectory}")"
213+
testFilenameOS="$(convertToWindowsPath "${testFilename}")"
214+
else
215+
# Handle linux/unix based systems
216+
nologParam="/nolog"
217+
218+
testFileOS="${testFile}"
219+
testDirectoryOS="${testDirectory}"
220+
testFilenameOS="${testFilename}"
221+
fi
222+
185223
# Make sure SQLPATH is not set for SQLcl execution so no login.sql
186224
# script is runs
187225
export SQLPATH=""
@@ -202,7 +240,7 @@ function main() {
202240
set verify on
203241
set echo on
204242
show connection
205-
@ "${testFile}" "${functionUniqueIdentifier}" "${testDirectory}"
243+
@ "${testFileOS}" "${functionUniqueIdentifier}" "${testDirectoryOS}"
206244
EOF
207245
testResultCode=$?
208246

@@ -223,10 +261,10 @@ function main() {
223261
printf -- 'set verify on\n'
224262
printf -- 'set echo on\n'
225263
printf -- 'show connection\n'
226-
printf -- '@ "%s" "%s" "%s"' "${testFile}" "${functionUniqueIdentifier}" "${testDirectory}"
264+
printf -- '@ "%s" "%s" "%s"' "${testFileOS}" "${functionUniqueIdentifier}" "${testDirectoryOS}"
227265
} > "${wrapperFile}"
228266

229-
"${sqlclBinary}" -noupdates /nolog "@${wrapperFile}" 1>>"${logFile}" 2>&1
267+
"${sqlclBinary}" -noupdates "${nologParam}" "@${wrapperFile}" 1>>"${logFile}" 2>&1
230268
testResultCode=$?
231269

232270
rm "${wrapperFile}"
@@ -247,7 +285,7 @@ function main() {
247285
set verify on
248286
set echo on
249287
show connection
250-
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -changelog-file ${testFilename}
288+
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -changelog-file ${testFilenameOS}
251289
EOF
252290
testResultCode=$?
253291
elif [[ "${testType}" = "${testTypeSqlclLiquibaseSearchPath}" ]]; then
@@ -265,7 +303,7 @@ function main() {
265303
set verify on
266304
set echo on
267305
show connection
268-
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -search-path ${testDirectory} -changelog-file ${testFilename}
306+
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -search-path ${testDirectoryOS} -changelog-file ${testFilenameOS}
269307
EOF
270308
testResultCode=$?
271309
fi
@@ -606,8 +644,8 @@ function main() {
606644
printf -- '\n' | tee -a "${logMainFile}"
607645
fi
608646

609-
sqlParamsWithoutPassword+=("-user" "${databaseUsername}" "-url" "${databaseConnectIdentifier}")
610-
sqlParamsWithPassword+=("${sqlParamsWithoutPassword[@]}" "-password" "${databasePassword}")
647+
sqlParamsWithoutPassword+=("-user" "\"${databaseUsername}\"" "-url" "\"${databaseConnectIdentifier}\"")
648+
sqlParamsWithPassword+=("${sqlParamsWithoutPassword[@]}" "-password" "\"${databasePassword}\"")
611649

612650
if ! "${sqlclBinary}" "${sqlParamsDirectConnect[@]}" "${sqlParamsWithPassword[@]}" 1>>"${logMainFile}" 2>&1 <<- EOF
613651
show connection

source/sqlcl_direct_unit_tests/sqlcl-liquibase-default-file-relative-to-script-absolute/script.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
-- Make sure the liquibase changelog table exists
2+
prompt "Run liquibase validate"
23
liquibase validate -database-changelog-table-name &1._changelog -changelog-file changelog.xml
34

45
-- Call to see if functionality works
6+
prompt "Run liquibase update"
57
liquibase update -database-changelog-table-name &1._changelog -changelog-file changelog.xml -defaults-file liquibase.properties
68

79
-- See if any changesets were run
10+
prompt "Check changesets ran"
811
declare
912
c_table_name constant varchar2(255 char) := '&1._changelog';
1013
l_count number;

source/sqlcl_direct_unit_tests/sqlcl-liquibase-default-file-relative-to-script-relative/script.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
-- Make sure the liquibase changelog table exists
2+
prompt "Run liquibase validate"
23
liquibase validate -database-changelog-table-name &1._changelog -changelog-file changelog.xml
34

45
-- Call to see if functionality works
6+
prompt "Run liquibase update"
57
liquibase update -database-changelog-table-name &1._changelog -changelog-file changelog.xml -defaults-file liquibase.properties
68

79
-- See if any changesets were run
10+
prompt "Check changesets ran"
811
declare
912
c_table_name constant varchar2(255 char) := '&1._changelog';
1013
l_count number;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
liquibase update -database-changelog-table-name &1._changelog -search-path / -defaults-file &2/sqlcl-liquibase-defaults-file-respected/liquibase.properties -changelog-file &2/sqlcl-liquibase-defaults-file-respected/changelog.xml
1+
liquibase update -database-changelog-table-name &1._changelog -search-path &2 -defaults-file sqlcl-liquibase-defaults-file-respected/liquibase.properties -changelog-file sqlcl-liquibase-defaults-file-respected/changelog.xml

0 commit comments

Comments
 (0)