mirror of
https://github.com/scopatz/nanorc
synced 2025-06-20 13:40:07 +02:00
Test program versions
This commit is contained in:
parent
c40ab81504
commit
f064485bd6
70
tests.sh
70
tests.sh
@ -2,53 +2,53 @@
|
|||||||
# Shellcheck the script
|
# Shellcheck the script
|
||||||
# Note: using bash for more power in testing (the final user doesn't need it).
|
# Note: using bash for more power in testing (the final user doesn't need it).
|
||||||
|
|
||||||
|
# Global Variables
|
||||||
|
G_NANO_VERSION=""
|
||||||
|
G_SHELLCHECK_VERSION=""
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
# Test Version
|
# Compare Version
|
||||||
# Receives two parameters in x.x.x format.
|
# Compare the first version (x.x.x format) against second one.
|
||||||
# Returns true or false
|
# Returns true if $1 => $2, false otherwise.
|
||||||
# Sources:
|
# Sources:
|
||||||
# https://unix.stackexchange.com/questions/285924/how-to-compare-a-programs-version-in-a-shell-script
|
# https://unix.stackexchange.com/questions/285924/how-to-compare-a-programs-version-in-a-shell-script
|
||||||
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
|
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
|
||||||
test_version (){
|
# Test table:
|
||||||
|
# req | get | test | res
|
||||||
|
# ------+-------+-------+-------
|
||||||
|
# 2.0.0 | 1.0.0 | 1.0.0 | true
|
||||||
|
# 1.0.0 | 2.0.0 | 1.0.0 | false
|
||||||
|
# 0.5.3 | 0.5.3 | 0.5.3 | true
|
||||||
|
f_compare_version(){
|
||||||
|
local required_v="$1"
|
||||||
|
local getted_v="$2"
|
||||||
|
|
||||||
|
# First: check if equal
|
||||||
|
if [ "$required_v" = "$getted_v" ]; then
|
||||||
|
return true;
|
||||||
|
fi
|
||||||
|
|
||||||
currentver="$(gcc -dumpversion)"
|
# Second: check if greater or lesser
|
||||||
requiredver="5.0.0"
|
local test_v=$(printf "%s\n%s" "$greater_v" "$lesser_v" | sort -V | head -n 1)
|
||||||
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]; then
|
case $test_v in
|
||||||
echo "Greater than or equal to 5.0.0"
|
$getted_v) return true;
|
||||||
else
|
$required_v) return false;
|
||||||
echo "Less than 5.0.0"
|
*) return false;
|
||||||
fi
|
esac
|
||||||
|
|
||||||
###################
|
|
||||||
|
|
||||||
verlte() {
|
|
||||||
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
verlt() {
|
# Test Functions
|
||||||
[ "$1" = "$2" ] && return 1 || verlte $1 $2
|
|
||||||
|
f_test_nano_version() {
|
||||||
|
local version="nano --version | cut -d ' ' -f 4"
|
||||||
|
return f_compare_version $G_NANO_VERSION $version
|
||||||
}
|
}
|
||||||
|
|
||||||
##################
|
f_test_nano_version() {
|
||||||
|
local version="nano --version | cut -d ' ' -f 8"
|
||||||
|
return f_compare_version $G_SHELLCHECK_VERSION $version
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Tests
|
|
||||||
|
|
||||||
get_nano_version () {
|
|
||||||
local tested_version=""
|
|
||||||
# x.x.x
|
|
||||||
local actual_version="nano --version | cut -d ' ' -f 4"
|
|
||||||
}
|
|
||||||
|
|
||||||
nano --version
|
|
||||||
shellcheck --version
|
|
||||||
|
|
||||||
# ....shellcheck -f diff *.sh | git apply | git commit -a -m "Shellcheck fast corrections"
|
# ....shellcheck -f diff *.sh | git apply | git commit -a -m "Shellcheck fast corrections"
|
||||||
shellcheck *.sh
|
shellcheck *.sh
|
||||||
|
Loading…
x
Reference in New Issue
Block a user