Skip to content

Commit

Permalink
Reverted fetch-cobolcheck and fetch-cobolcheck.ps1 scripts. (#158)
Browse files Browse the repository at this point in the history
* Reverted fetch-cobolcheck and fetch-cobolcheck.ps1 scripts.

* fetch-cobolcheck-fixes:

- 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}.

* fetch-cobolcheck-fixes: Restored the previous file permissions.

* fetch-cobolcheck-fixes: Added command for the /home/simadovakin/cobolcheck/ creation in the fetch-cobolcheck,ps1
  • Loading branch information
SimaDovakin authored Aug 24, 2024
1 parent f2095c6 commit 6c52fb9
Show file tree
Hide file tree
Showing 189 changed files with 743 additions and 808 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
7 changes: 5 additions & 2 deletions bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

set -eo pipefail
# set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

Expand Down Expand Up @@ -45,10 +45,13 @@ get_download_url() {
}

main() {
output_path="/usr/local/bin/cobolcheck${ext}"
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
6 changes: 3 additions & 3 deletions bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputDir = Join-Path -Path $HOME -ChildPath "cobolcheck"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
$outputDir = Join-Path -Path "${HOME}" "cobolcheck"
New-Item -Path "${outputDir}" -ItemType "directory"
$outputFile = Join-Path -Path "${outputDir}" "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
7 changes: 5 additions & 2 deletions exercises/practice/acronym/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

set -eo pipefail
# set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

Expand Down Expand Up @@ -45,10 +45,13 @@ get_download_url() {
}

main() {
output_path="/usr/local/bin/cobolcheck${ext}"
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
6 changes: 3 additions & 3 deletions exercises/practice/acronym/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputDir = Join-Path -Path $HOME -ChildPath "cobolcheck"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
$outputDir = Join-Path -Path "${HOME}" "cobolcheck"
New-Item -Path "${outputDir}" -ItemType "directory"
$outputFile = Join-Path -Path "${outputDir}" "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
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
7 changes: 5 additions & 2 deletions exercises/practice/all-your-base/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

set -eo pipefail
# set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

Expand Down Expand Up @@ -45,10 +45,13 @@ get_download_url() {
}

main() {
output_path="/usr/local/bin/cobolcheck${ext}"
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
6 changes: 3 additions & 3 deletions exercises/practice/all-your-base/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputDir = Join-Path -Path $HOME -ChildPath "cobolcheck"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
$outputDir = Join-Path -Path "${HOME}" "cobolcheck"
New-Item -Path "${outputDir}" -ItemType "directory"
$outputFile = Join-Path -Path "${outputDir}" "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
7 changes: 5 additions & 2 deletions exercises/practice/allergies/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

set -eo pipefail
# set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

Expand Down Expand Up @@ -45,10 +45,13 @@ get_download_url() {
}

main() {
output_path="/usr/local/bin/cobolcheck${ext}"
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
6 changes: 3 additions & 3 deletions exercises/practice/allergies/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputDir = Join-Path -Path $HOME -ChildPath "cobolcheck"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
$outputDir = Join-Path -Path "${HOME}" "cobolcheck"
New-Item -Path "${outputDir}" -ItemType "directory"
$outputFile = Join-Path -Path "${outputDir}" "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
7 changes: 5 additions & 2 deletions exercises/practice/anagram/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

set -eo pipefail
# set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

Expand Down Expand Up @@ -45,10 +45,13 @@ get_download_url() {
}

main() {
output_path="/usr/local/bin/cobolcheck${ext}"
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
6 changes: 3 additions & 3 deletions exercises/practice/anagram/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputDir = Join-Path -Path $HOME -ChildPath "cobolcheck"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
$outputDir = Join-Path -Path "${HOME}" "cobolcheck"
New-Item -Path "${outputDir}" -ItemType "directory"
$outputFile = Join-Path -Path "${outputDir}" "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
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
7 changes: 5 additions & 2 deletions exercises/practice/armstrong-numbers/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

set -eo pipefail
# set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

Expand Down Expand Up @@ -45,10 +45,13 @@ get_download_url() {
}

main() {
output_path="/usr/local/bin/cobolcheck${ext}"
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
6 changes: 3 additions & 3 deletions exercises/practice/armstrong-numbers/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Get-DownloadUrl {
}

$downloadUrl = Get-DownloadUrl
$outputDir = Join-Path -Path $HOME -ChildPath "cobolcheck"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
$outputDir = Join-Path -Path "${HOME}" "cobolcheck"
New-Item -Path "${outputDir}" -ItemType "directory"
$outputFile = Join-Path -Path "${outputDir}" "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
Loading

0 comments on commit 6c52fb9

Please sign in to comment.