Skip to content

Commit

Permalink
Shell: upgraded test libraries into HestiaKERNEL
Browse files Browse the repository at this point in the history
Since the test framework is reusable, it's best to upgrade the
existing ones into HestiaKERNEL library instead. Hence, let's do
this.

This patch upgrades test libraries into HestiaKERNEL in Shell/
directory.

Co-authored-by: Shuralyov, Jean <[email protected]>
Co-authored-by: Galyna, Cory <[email protected]>
Co-authored-by: (Holloway) Chew, Kean Ho <[email protected]>
Signed-off-by: (Holloway) Chew, Kean Ho <[email protected]>
  • Loading branch information
3 people committed Dec 25, 2024
1 parent 63e63d0 commit 0c8fbd8
Show file tree
Hide file tree
Showing 61 changed files with 3,252 additions and 263 deletions.
61 changes: 61 additions & 0 deletions Shell/libraries/HestiaKERNEL/FS/Get_Files.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Errors\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\FS\Is_Directory.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\FS\Is_File.ps1"




function HestiaKERNEL-Get-Files {
param (
[string]$___directory,
[string]$___filter,
[int]$___recursive
)


# validate input
if ($(HestiaKERNEL-Is-Directory-FS $___directory) -ne ${env:HestiaKERNEL_ERROR_OK}) {
return [string[]]@()
}


# execute
[System.Collections.Generic.List[string]]$___list = @()
foreach ($____item in (Get-ChildItem $___directory)) {
if ($(HestiaKERNEL-Is-Directory-FS $____item) -eq ${env:HestiaKERNEL_ERROR_OK}) {
if ($___recursive -eq 0) {
continue
} elseif ($___recursive -gt 0) {
$___results = HestiaKERNEL-Get-Files $____item.FullName `
$___filter `
($___recursive - 1)
} else {
$___results = HestiaKERNEL-Get-Files $____item.FullName `
$___filter `
-1
}

foreach ($___result in $___results) {
$___list.Add($___result)
}
} elseif ($(HestiaKERNEL-Is-File-FS $____item) -eq ${env:HestiaKERNEL_ERROR_OK}) {
if ($____item.Name -like "*${___filter}*") {
$___list.Add($____item.FullName)
}
}
}


# report status
return [string[]]$___list
}
61 changes: 61 additions & 0 deletions Shell/libraries/HestiaKERNEL/FS/Get_Files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/FS/Is_Directory.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/FS/Is_File.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Number/Is_Number.sh"




HestiaKERNEL_Get_Files_FS() {
#___directory="$1"
#___filter="$2"
#___recursive="$3"


# validate input
if [ $(HestiaKERNEL_Is_Directory_FS "$1") -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- ""
return $HestiaKERNEL_ERROR_ENTITY_INVALID
fi


# execute
for ____item in "$1"/*; do
if [ $(HestiaKERNEL_Is_Directory_FS "$____item") -eq $HestiaKERNEL_ERROR_OK ]; then
if [ $(HestiaKERNEL_Is_Number "$3") -ne $HestiaKERNEL_ERROR_OK ]; then
continue
fi

if [ $3 -eq 0 ]; then
continue
elif [ $3 -gt 0 ]; then
HestiaKERNEL_Get_Files_FS "$____item" "$2" "$(($3 - 1))"
else
HestiaKERNEL_Get_Files_FS "$____item" "$2" "$3"
fi
elif [ $(HestiaKERNEL_Is_File_FS "$____item") -eq $HestiaKERNEL_ERROR_OK ]; then
____filename="${____item##*/}"

if [ "$2" = "" ]; then
printf -- "%s\n" "$____item"
elif [ ! "${____filename##*"$2"}" = "$____filename" ]; then
printf -- "%s\n" "$____item"
fi
fi
done


# report status
return $HestiaKERNEL_ERROR_OK
}
36 changes: 36 additions & 0 deletions Shell/libraries/HestiaKERNEL/FS/Is_Directory.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\hestiaKERNEL\Errors\Error_Codes.sh"




function HestiaKERNEL-Is-Directory-FS {
param (
[string]$___target
)


# validate input
if ($___target -eq "") {
return ${env:hestiaKERNEL_ERROR_DATA_EMPTY}
}


# execute
if (Test-Path -PathType Container -Path $___target -ErrorAction SilentlyContinue) {
return ${env:hestiaKERNEL_ERROR_OK}
}


# report status
return ${env:hestiaKERNEL_ERROR_DATA_BAD}
}
38 changes: 38 additions & 0 deletions Shell/libraries/HestiaKERNEL/FS/Is_Directory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh"




HestiaKERNEL_Is_Directory_FS() {
#___target="$1"


# validate input
if [ "$1" = "" ]; then
printf -- "%d" "$HestiaKERNEL_ERROR_DATA_EMPTY"
return $HestiaKERNEL_ERROR_DATA_EMPTY
fi


# execute
if [ -d "$1" ]; then
printf -- "%d" "$HestiaKERNEL_ERROR_OK"
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" "$HestiaKERNEL_ERROR_DATA_BAD"
return $HestiaKERNEL_ERROR_DATA_BAD
}
36 changes: 36 additions & 0 deletions Shell/libraries/HestiaKERNEL/FS/Is_File.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\hestiaKERNEL\Errors\Error_Codes.sh"




function HestiaKERNEL-Is-File-FS {
param (
[string]$___target
)


# validate input
if ($___target -eq "") {
return ${env:hestiaKERNEL_ERROR_DATA_EMPTY}
}


# execute
if (Test-Path -PathType leaf -Path $___target -ErrorAction SilentlyContinue) {
return ${env:hestiaKERNEL_ERROR_OK}
}


# report status
return ${env:hestiaKERNEL_ERROR_DATA_BAD}
}
38 changes: 38 additions & 0 deletions Shell/libraries/HestiaKERNEL/FS/Is_File.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh"




HestiaKERNEL_Is_File_FS() {
#___target="$1"


# validate input
if [ "$1" = "" ]; then
printf -- "%d" "$HestiaKERNEL_ERROR_DATA_EMPTY"
return $HestiaKERNEL_ERROR_DATA_EMPTY
fi


# execute
if [ -f "$1" ]; then
printf -- "%d" "$HestiaKERNEL_ERROR_OK"
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" "$HestiaKERNEL_ERROR_DATA_BAD"
return $HestiaKERNEL_ERROR_DATA_BAD
}
2 changes: 1 addition & 1 deletion Shell/libraries/HestiaKERNEL/Number/Is_Number.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ HestiaKERNEL_Is_Number() {

# execute
case "$1" in
*[!0123456789_]*)
*[!+-0123456789_]*)
printf -- "%d" $HestiaKERNEL_ERROR_DATA_INVALID
return $HestiaKERNEL_ERROR_DATA_INVALID
;;
Expand Down
17 changes: 17 additions & 0 deletions Shell/libraries/HestiaKERNEL/Test/Codes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.




# faciliate test framework
${env:HestiaKERNEL_TEST_PASSED} = 0
${env:HestiaKERNEL_TEST_FAILED} = 1
18 changes: 18 additions & 0 deletions Shell/libraries/HestiaKERNEL/Test/Codes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.




# faciliate test framework
export HestiaKERNEL_TEST_PASSED=0
export HestiaKERNEL_TEST_FAILED=1
55 changes: 55 additions & 0 deletions Shell/libraries/HestiaKERNEL/Test/Exec_Test_Case.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Test\Codes.sh"




function HestiaKERNEL-Exec-Test-Case {
param (
[string]$___filepath,
[string]$___report_only_failed
)


# validate input
if ($___filepath -eq "") {
return ${env:HestiaKERNEL_TEST_FAILED}
}

if (-not (Test-Path -Path $___filepath -PathType Leaf)) {
return ${env:HestiaKERNEL_TEST_FAILED}
}


# execute
$___process = & {
$___output = . $___script 2>&1
if ($LASTEXITCODE -eq ${env:HestiaKERNEL_TEST_PASSED}) {
if ($___report_only_failed -eq "") {
$null = Write-Host "${___output}"
}

return ${env:HestiaKERNEL_TEST_PASSED}
}

$null = Write-Host "${___output}"
return ${env:HestiaKERNEL_TEST_FAILED}
}

if ($___process -eq ${env:HestiaKERNEL_TEST_PASSED}) {
return ${env:HestiaKERNEL_TEST_PASSED}
}


# report status
return ${env:HestiaKERNEL_TEST_FAILED}
}
Loading

0 comments on commit 0c8fbd8

Please sign in to comment.