mirror of
https://github.com/TheLocehiliosan/yadm
synced 2026-03-02 03:49:29 +00:00
Support WSL detection (#61)
`uname -s` was already being executed every run for *cygwin* detection. I've consolidated all of the OS detection into a single function. This also fixed the problem of running `uname -s` twice for the `alt` command.
This commit is contained in:
76
test/006_unit_set_operating_system.bats
Normal file
76
test/006_unit_set_operating_system.bats
Normal file
@@ -0,0 +1,76 @@
|
||||
load common
|
||||
load_fixtures
|
||||
|
||||
@test "Default OS" {
|
||||
echo "
|
||||
By default, the value of OPERATING_SYSTEM should be reported by uname -s
|
||||
"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
status=0
|
||||
output=$( set_operating_system; echo "$OPERATING_SYSTEM" ) || {
|
||||
status=$?
|
||||
true
|
||||
}
|
||||
|
||||
expected=$(uname -s 2>/dev/null)
|
||||
|
||||
echo "output=$output"
|
||||
echo "expect=$expected"
|
||||
|
||||
[ "$status" == 0 ]
|
||||
[ "$output" = "$expected" ]
|
||||
}
|
||||
|
||||
@test "Detect no WSL" {
|
||||
echo "
|
||||
When /proc/version does not contain Microsoft, report uname -s
|
||||
"
|
||||
|
||||
echo "proc version exists" > "$BATS_TMPDIR/proc_version"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
# shellcheck disable=SC2034
|
||||
PROC_VERSION="$BATS_TMPDIR/proc_version"
|
||||
status=0
|
||||
output=$( set_operating_system; echo "$OPERATING_SYSTEM" ) || {
|
||||
status=$?
|
||||
true
|
||||
}
|
||||
|
||||
expected=$(uname -s 2>/dev/null)
|
||||
|
||||
echo "output=$output"
|
||||
echo "expect=$expected"
|
||||
|
||||
[ "$status" == 0 ]
|
||||
[ "$output" = "$expected" ]
|
||||
}
|
||||
|
||||
@test "Detect WSL" {
|
||||
echo "
|
||||
When /proc/version contains Microsoft, report WSL
|
||||
"
|
||||
|
||||
echo "proc version contains Microsoft in it" > "$BATS_TMPDIR/proc_version"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
# shellcheck disable=SC2034
|
||||
PROC_VERSION="$BATS_TMPDIR/proc_version"
|
||||
status=0
|
||||
output=$( set_operating_system; echo "$OPERATING_SYSTEM" ) || {
|
||||
status=$?
|
||||
true
|
||||
}
|
||||
|
||||
expected="WSL"
|
||||
|
||||
echo "output=$output"
|
||||
echo "expect=$expected"
|
||||
|
||||
[ "$status" == 0 ]
|
||||
[ "$output" = "$expected" ]
|
||||
}
|
||||
@@ -94,7 +94,7 @@ function test_alt() {
|
||||
# shellcheck source=/dev/null
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
process_global_args -Y "$T_DIR_YADM"
|
||||
test_cygwin
|
||||
set_operating_system
|
||||
configure_paths
|
||||
|
||||
status=0
|
||||
|
||||
Reference in New Issue
Block a user