Skip to content

Commit

Permalink
fetch-cobolcheck-fixes:
Browse files Browse the repository at this point in the history
- Renamed bin/sync-fetch-cobolcheck-files to bin/sync-exercise-files and
  added synchronization for test.sh and test.ps1 files.
- Added bin/exercise_test.sh and bin/exercise_test.ps1 as templates for
  test.sh and test.ps1 respectively.
- Changed cobolcheck location to $HOME/cobolcheck/cobolcheck{,exe}.
  • Loading branch information
SimaDovakin committed Aug 10, 2024
1 parent b3583d7 commit 229c736
Show file tree
Hide file tree
Showing 189 changed files with 555 additions and 1,043 deletions.
19 changes: 19 additions & 0 deletions bin/exercise_test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"

if (![System.IO.File]::Exists("$cobolcheck")){
$fetchCobolcheckPath = Join-Path -Path "${PSScriptRoot}" "bin" "fetch-cobolcheck.ps1"
echo $fetchCobolcheckPath
Write-Output "Cobolcheck not found. Trying to fetch it."
& "${fetchCobolcheckPath}"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
exit $Lastexitcode
}
16 changes: 16 additions & 0 deletions bin/exercise_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/
SLUG=${1:-$(basename "${SCRIPT_DIR}")}
COBOLCHECK="${HOME}/cobolcheck/cobolcheck"

if [ ! -f "${COBOLCHECK}" ]; then
echo "Cobolcheck not found, try to fetch it."
cd $SCRIPT_DIR/bin/
bash fetch-cobolcheck
fi
cd $SCRIPT_DIR
$COBOLCHECK -p $SLUG

# compile and run
echo "COMPILE AND RUN TEST"
cobc -xj test.cob
12 changes: 3 additions & 9 deletions bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ get_download_url() {
}

main() {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD == */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

output_dir="${HOME}/cobolcheck"
mkdir -p "${output_dir}"
output_path="${output_dir}/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
echo "Cobolcheck has been downloaded to ${output_path}"
}

main
2 changes: 1 addition & 1 deletion bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
$outputFile = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
2 changes: 2 additions & 0 deletions bin/sync-fetch-cobolcheck-files → bin/sync-exercise-files
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ for test_dir in exercises/{concept,practice}/*; do
for file in fetch-cobolcheck fetch-cobolcheck.ps1; do
cp "bin/${file}" "${test_dir}/bin/${file}"
done
cp "bin/exercise_test.sh" "${test_dir}/test.sh"
cp "bin/exercise_test.ps1" "${test_dir}/test.ps1"
done
12 changes: 3 additions & 9 deletions exercises/practice/acronym/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ get_download_url() {
}

main() {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD == */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

output_dir="${HOME}/cobolcheck"
mkdir -p "${output_dir}"
output_path="${output_dir}/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
echo "Cobolcheck has been downloaded to ${output_path}"
}

main
2 changes: 1 addition & 1 deletion exercises/practice/acronym/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
$outputFile = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
12 changes: 5 additions & 7 deletions exercises/practice/acronym/test.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue
$cobolcheck = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"

if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
if (![System.IO.File]::Exists("$cobolcheck")){
$fetchCobolcheckPath = Join-Path -Path "${PSScriptRoot}" "bin" "fetch-cobolcheck.ps1"
echo $fetchCobolcheckPath
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
& "${fetchCobolcheckPath}"
}

Write-Output "Run cobolcheck."
Expand Down
8 changes: 2 additions & 6 deletions exercises/practice/acronym/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/
SLUG=${1:-$(basename "${SCRIPT_DIR}")}
COBOLCHECK=./bin/cobolcheck
COBOLCHECK="${HOME}/cobolcheck/cobolcheck"

WHICH_COBOLCHECK=$(which cobolcheck)
if [[ $? -eq 0 ]] ; then
echo "Found cobolcheck, using $COBOLCHECK"
COBOLCHECK=$WHICH_COBOLCHECK
elif [ ! -f $SCRIPT_DIR/bin/cobolcheck ]; then
if [ ! -f "${COBOLCHECK}" ]; then
echo "Cobolcheck not found, try to fetch it."
cd $SCRIPT_DIR/bin/
bash fetch-cobolcheck
Expand Down
12 changes: 3 additions & 9 deletions exercises/practice/all-your-base/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ get_download_url() {
}

main() {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD == */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

output_dir="${HOME}/cobolcheck"
mkdir -p "${output_dir}"
output_path="${output_dir}/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
echo "Cobolcheck has been downloaded to ${output_path}"
}

main
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
$outputFile = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
12 changes: 5 additions & 7 deletions exercises/practice/all-your-base/test.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue
$cobolcheck = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"

if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
if (![System.IO.File]::Exists("$cobolcheck")){
$fetchCobolcheckPath = Join-Path -Path "${PSScriptRoot}" "bin" "fetch-cobolcheck.ps1"
echo $fetchCobolcheckPath
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
& "${fetchCobolcheckPath}"
}

Write-Output "Run cobolcheck."
Expand Down
8 changes: 2 additions & 6 deletions exercises/practice/all-your-base/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/
SLUG=${1:-$(basename "${SCRIPT_DIR}")}
COBOLCHECK=./bin/cobolcheck
COBOLCHECK="${HOME}/cobolcheck/cobolcheck"

WHICH_COBOLCHECK=$(which cobolcheck)
if [[ $? -eq 0 ]] ; then
echo "Found cobolcheck, using $COBOLCHECK"
COBOLCHECK=$WHICH_COBOLCHECK
elif [ ! -f $SCRIPT_DIR/bin/cobolcheck ]; then
if [ ! -f "${COBOLCHECK}" ]; then
echo "Cobolcheck not found, try to fetch it."
cd $SCRIPT_DIR/bin/
bash fetch-cobolcheck
Expand Down
12 changes: 3 additions & 9 deletions exercises/practice/allergies/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ get_download_url() {
}

main() {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD == */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

output_dir="${HOME}/cobolcheck"
mkdir -p "${output_dir}"
output_path="${output_dir}/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
echo "Cobolcheck has been downloaded to ${output_path}"
}

main
2 changes: 1 addition & 1 deletion exercises/practice/allergies/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
$outputFile = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
12 changes: 5 additions & 7 deletions exercises/practice/allergies/test.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue
$cobolcheck = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"

if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
if (![System.IO.File]::Exists("$cobolcheck")){
$fetchCobolcheckPath = Join-Path -Path "${PSScriptRoot}" "bin" "fetch-cobolcheck.ps1"
echo $fetchCobolcheckPath
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
& "${fetchCobolcheckPath}"
}

Write-Output "Run cobolcheck."
Expand Down
8 changes: 2 additions & 6 deletions exercises/practice/allergies/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/
SLUG=${1:-$(basename "${SCRIPT_DIR}")}
COBOLCHECK=./bin/cobolcheck
COBOLCHECK="${HOME}/cobolcheck/cobolcheck"

WHICH_COBOLCHECK=$(which cobolcheck)
if [[ $? -eq 0 ]] ; then
echo "Found cobolcheck, using $COBOLCHECK"
COBOLCHECK=$WHICH_COBOLCHECK
elif [ ! -f $SCRIPT_DIR/bin/cobolcheck ]; then
if [ ! -f "${COBOLCHECK}" ]; then
echo "Cobolcheck not found, try to fetch it."
cd $SCRIPT_DIR/bin/
bash fetch-cobolcheck
Expand Down
12 changes: 3 additions & 9 deletions exercises/practice/anagram/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ get_download_url() {
}

main() {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD == */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

output_dir="${HOME}/cobolcheck"
mkdir -p "${output_dir}"
output_path="${output_dir}/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
echo "Cobolcheck has been downloaded to ${output_path}"
}

main
2 changes: 1 addition & 1 deletion exercises/practice/anagram/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
$outputFile = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
12 changes: 5 additions & 7 deletions exercises/practice/anagram/test.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue
$cobolcheck = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"

if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
if (![System.IO.File]::Exists("$cobolcheck")){
$fetchCobolcheckPath = Join-Path -Path "${PSScriptRoot}" "bin" "fetch-cobolcheck.ps1"
echo $fetchCobolcheckPath
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
& "${fetchCobolcheckPath}"
}

Write-Output "Run cobolcheck."
Expand Down
8 changes: 2 additions & 6 deletions exercises/practice/anagram/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/
SLUG=${1:-$(basename "${SCRIPT_DIR}")}
COBOLCHECK=./bin/cobolcheck
COBOLCHECK="${HOME}/cobolcheck/cobolcheck"

WHICH_COBOLCHECK=$(which cobolcheck)
if [[ $? -eq 0 ]] ; then
echo "Found cobolcheck, using $COBOLCHECK"
COBOLCHECK=$WHICH_COBOLCHECK
elif [ ! -f $SCRIPT_DIR/bin/cobolcheck ]; then
if [ ! -f "${COBOLCHECK}" ]; then
echo "Cobolcheck not found, try to fetch it."
cd $SCRIPT_DIR/bin/
bash fetch-cobolcheck
Expand Down
12 changes: 3 additions & 9 deletions exercises/practice/armstrong-numbers/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ get_download_url() {
}

main() {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD == */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

output_dir="${HOME}/cobolcheck"
mkdir -p "${output_dir}"
output_path="${output_dir}/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
echo "Cobolcheck has been downloaded to ${output_path}"
}

main
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
$outputFile = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
12 changes: 5 additions & 7 deletions exercises/practice/armstrong-numbers/test.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue
$cobolcheck = Join-Path -Path "${HOME}" "cobolcheck" "cobolcheck.exe"

if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
if (![System.IO.File]::Exists("$cobolcheck")){
$fetchCobolcheckPath = Join-Path -Path "${PSScriptRoot}" "bin" "fetch-cobolcheck.ps1"
echo $fetchCobolcheckPath
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
& "${fetchCobolcheckPath}"
}

Write-Output "Run cobolcheck."
Expand Down
8 changes: 2 additions & 6 deletions exercises/practice/armstrong-numbers/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/
SLUG=${1:-$(basename "${SCRIPT_DIR}")}
COBOLCHECK=./bin/cobolcheck
COBOLCHECK="${HOME}/cobolcheck/cobolcheck"

WHICH_COBOLCHECK=$(which cobolcheck)
if [[ $? -eq 0 ]] ; then
echo "Found cobolcheck, using $COBOLCHECK"
COBOLCHECK=$WHICH_COBOLCHECK
elif [ ! -f $SCRIPT_DIR/bin/cobolcheck ]; then
if [ ! -f "${COBOLCHECK}" ]; then
echo "Cobolcheck not found, try to fetch it."
cd $SCRIPT_DIR/bin/
bash fetch-cobolcheck
Expand Down
Loading

0 comments on commit 229c736

Please sign in to comment.