generated from stubbfel/nix-project-template
draft
This commit is contained in:
79
spec/patch-manjaro-sway-mirror-for-arm_spec.sh
Normal file
79
spec/patch-manjaro-sway-mirror-for-arm_spec.sh
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/bin/env sh
|
||||
|
||||
Describe "patch-manjaro-sway-mirror-for-arm.sh - Test Suite"
|
||||
|
||||
test_root=$(mktemp -d)
|
||||
target_file="${test_root}/usr/bin/manjaro-sway-mirrors"
|
||||
custom_file="${target_file}-custom"
|
||||
custom_replace_pattern="replaced"
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
test_content='curl -s "https://pkg.manjaro-sway.download/$(pacman-mirrors -G)/testing"'
|
||||
|
||||
setup_test_data() {
|
||||
export MSMAP_TARGET_ROOT="${test_root}"
|
||||
mkdir -p "${test_root}/usr/bin"
|
||||
|
||||
echo "${test_content}" > "${target_file}"
|
||||
cp -f "${target_file}" "${custom_file}"
|
||||
}
|
||||
|
||||
teardown_test_data() {
|
||||
unset MSMAP_TARGET_ROOT
|
||||
rm -rf "${test_root}"
|
||||
}
|
||||
|
||||
BeforeEach 'setup_test_data'
|
||||
AfterEach 'teardown_test_data'
|
||||
|
||||
Describe "Help message"
|
||||
It "should display the usage information"
|
||||
When run src/patch-manjaro-sway-mirror-for-arm.sh --help
|
||||
The output should include "Usage: patch-manjaro-sway-mirror-for-arm.sh"
|
||||
The status should be success
|
||||
End
|
||||
End
|
||||
|
||||
Describe "Dry run"
|
||||
It "should perform a dry run without modifying the target file"
|
||||
When run src/patch-manjaro-sway-mirror-for-arm.sh --dry-run
|
||||
The status should be success
|
||||
The contents of file "${target_file}" should equal "${test_content}"
|
||||
# shellcheck disable=SC2016
|
||||
The output should equal "sed -i \"s|\\\$(pacman-mirrors -G)|\\\$(pacman-mirrors -G \| sed \\\"s/^arm-//\\\")|g\" \"${target_file}\"
|
||||
curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G | sed \"s/^arm-//\")/testing\""
|
||||
End
|
||||
End
|
||||
|
||||
Describe "Default values"
|
||||
It "should modify the target file with default values"
|
||||
When run src/patch-manjaro-sway-mirror-for-arm.sh
|
||||
The output should equal ""
|
||||
The status should be success
|
||||
The contents of file "${target_file}" should equal "curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G | sed \"s/^arm-//\")/testing\""
|
||||
End
|
||||
End
|
||||
|
||||
Describe "Custom target file and replace pattern"
|
||||
It "should modify the custom target file with the provided replace pattern"
|
||||
When run src/patch-manjaro-sway-mirror-for-arm.sh "${custom_file}" -r "${custom_replace_pattern}"
|
||||
The output should equal ""
|
||||
The status should be success
|
||||
The contents of file "${target_file}" should equal "${test_content}"
|
||||
The contents of file "$custom_file" should equal "curl -s \"https://pkg.manjaro-sway.download/replaced/testing\""
|
||||
End
|
||||
End
|
||||
|
||||
Describe "Positional arguments"
|
||||
custom_search_pattern="testing"
|
||||
|
||||
It "should modify the target file with positional arguments"
|
||||
When run src/patch-manjaro-sway-mirror-for-arm.sh "$custom_file" "${custom_search_pattern}" "${custom_replace_pattern}"
|
||||
The output should equal ""
|
||||
The status should be success
|
||||
The contents of file "${target_file}" should equal "${test_content}"
|
||||
The contents of file "$custom_file" should equal "curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G)/replaced\""
|
||||
End
|
||||
End
|
||||
End
|
||||
|
||||
24
spec/spec_helper.sh
Normal file
24
spec/spec_helper.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
# shellcheck shell=sh
|
||||
|
||||
# Defining variables and functions here will affect all specfiles.
|
||||
# Change shell options inside a function may cause different behavior,
|
||||
# so it is better to set them here.
|
||||
# set -eu
|
||||
|
||||
# This callback function will be invoked only once before loading specfiles.
|
||||
spec_helper_precheck() {
|
||||
# Available functions: info, warn, error, abort, setenv, unsetenv
|
||||
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION
|
||||
: minimum_version "0.28.1"
|
||||
}
|
||||
|
||||
# This callback function will be invoked after a specfile has been loaded.
|
||||
spec_helper_loaded() {
|
||||
:
|
||||
}
|
||||
|
||||
# This callback function will be invoked after core modules has been loaded.
|
||||
spec_helper_configure() {
|
||||
# Available functions: import, before_each, after_each, before_all, after_all
|
||||
: import 'support/custom_matcher'
|
||||
}
|
||||
Reference in New Issue
Block a user