mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
Merge commit 'b19a54d2f9d8a3e83366c638aace4cf3b5daa96e' as 'build/dobuild'
This commit is contained in:
95
build/dobuild/tests/10_get_container_id.bats
Normal file
95
build/dobuild/tests/10_get_container_id.bats
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
BINPATH="$(readlink -f "$BATS_TEST_DIRNAME/../bin")"
|
||||
PATH="$BINPATH:$PATH"
|
||||
}
|
||||
|
||||
print_cgroup_container() {
|
||||
cat <<EOF
|
||||
10:perf_event:/
|
||||
9:devices:/docker/$1
|
||||
8:memory:/docker/$1
|
||||
7:cpu,cpuacct:/docker/$1
|
||||
6:freezer:/docker/$1
|
||||
5:cpuset:/docker/$1
|
||||
4:pids:/docker/$1
|
||||
3:blkio:/docker/$1
|
||||
2:net_cls,net_prio:/docker/$1
|
||||
1:name=systemd:/docker/$1
|
||||
EOF
|
||||
}
|
||||
|
||||
print_cgroup_host() {
|
||||
cat <<EOF
|
||||
10:perf_event:/
|
||||
9:devices:/user.slice
|
||||
8:memory:/user.slice
|
||||
7:cpu,cpuacct:/user.slice
|
||||
6:freezer:/
|
||||
5:cpuset:/
|
||||
4:pids:/user.slice/user-1000.slice/session-2.scope
|
||||
3:blkio:/user.slice
|
||||
2:net_cls,net_prio:/
|
||||
1:name=systemd:/user.slice/user-1000.slice/session-2.scope
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "get_container_id of known id" {
|
||||
source get_container_id.sh || true
|
||||
|
||||
container_id_by_object() {
|
||||
return 0
|
||||
}
|
||||
|
||||
container_id 1234
|
||||
}
|
||||
|
||||
@test "get_container_id of unknown id" {
|
||||
source get_container_id.sh || true
|
||||
|
||||
container_id_by_object() {
|
||||
return 3
|
||||
}
|
||||
|
||||
run container_id 1234
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[ -z "$output" ]
|
||||
}
|
||||
|
||||
@test "get_container_id self-id by cgroup" {
|
||||
source get_container_id.sh || true
|
||||
|
||||
container_id_by_object() {
|
||||
if [ "$1" = '8422b85b7e25dbe4cbc79f4d76392c34b2da4529ef3bc104ad2e097d44859d58' ]; then
|
||||
echo "$1"
|
||||
else
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
container_id_by_cgroup < <(print_cgroup_container 8422b85b7e25dbe4cbc79f4d76392c34b2da4529ef3bc104ad2e097d44859d58)
|
||||
|
||||
run container_id_by_cgroup < <(print_cgroup_container 3a6630ef0bfe2ab9b296d66aef9a29beecf764e03cce61289d08e888f5015cbe)
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[ -z "$output" ]
|
||||
|
||||
run container_id_by_cgroup < <(print_cgroup_host)
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[ -z "$output" ]
|
||||
}
|
||||
|
||||
61
build/dobuild/tests/20_is_running_in_bg.bats
Normal file
61
build/dobuild/tests/20_is_running_in_bg.bats
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
BINPATH="$(readlink -f "$BATS_TEST_DIRNAME/../bin")"
|
||||
PATH="$BINPATH:$PATH"
|
||||
}
|
||||
|
||||
@test "is_running_in_bg has required dep 'ps'" {
|
||||
ps --version
|
||||
echo "ps incompatible"
|
||||
ps -o stat= -p "$$"
|
||||
}
|
||||
|
||||
@test "is_running_in_bg has required dep 'grep'" {
|
||||
grep --help
|
||||
echo "grep incompatible"
|
||||
echo 'Ss' | grep -vq -e '+$'
|
||||
}
|
||||
|
||||
@test "is_running_in_bg returns error when ps fails" {
|
||||
ps() {
|
||||
return 1
|
||||
}
|
||||
|
||||
run source is_running_in_bg.sh 1234
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "is_running_in_bg returns success when running in bg" {
|
||||
ps() {
|
||||
echo 'Ss'
|
||||
}
|
||||
|
||||
run source is_running_in_bg.sh 1234
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
is_running_in_bg.sh &
|
||||
}
|
||||
|
||||
@test "is_running_in_bg returns error when running in fg" {
|
||||
ps() {
|
||||
echo 'Ss+'
|
||||
}
|
||||
|
||||
run source is_running_in_bg.sh 1234
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
81
build/dobuild/tests/30_container_run.bats
Normal file
81
build/dobuild/tests/30_container_run.bats
Normal file
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
BINPATH="$(readlink -f "$BATS_TEST_DIRNAME/../bin")"
|
||||
PATH="$BINPATH:$PATH"
|
||||
IMAGE="${REGISTRY_PREFIX}docker:${DOCKER_VERSION}-dind"
|
||||
|
||||
export IMAGE
|
||||
}
|
||||
|
||||
@test "container_run has required deps docker" {
|
||||
"$DOCKER" --version
|
||||
echo "docker unreachable!?"
|
||||
echo "DOCKER_HOST=$DOCKER_HOST"
|
||||
"$DOCKER" info
|
||||
echo "docker failed to pull $IMAGE"
|
||||
"$DOCKER" pull "$IMAGE"
|
||||
}
|
||||
|
||||
@test "container_run run command in a new container" {
|
||||
run container_run "$IMAGE" echo 'Hello world'
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'Hello world' ]
|
||||
}
|
||||
|
||||
@test "container_run docker should be accessible by default" {
|
||||
run container_run "$IMAGE" docker version
|
||||
echo "DOCKER_HOST=$DOCKER_HOST"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "container_run docker should be inaccessible when DOCKER_HOST is set to empty" {
|
||||
DOCKER_HOST= run container_run "$IMAGE" docker version
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "container_run run command with piped output" {
|
||||
OUTPUT="$(container_run "$IMAGE" echo 'Piped output' | cat)"
|
||||
echo "$OUTPUT"
|
||||
[ "$OUTPUT" = 'Piped output' ]
|
||||
}
|
||||
|
||||
@test "container_run run command with piped input" {
|
||||
OUTPUT="$(echo 'Piped input' | container_run "$IMAGE" cat)"
|
||||
echo "$OUTPUT"
|
||||
[ "$OUTPUT" = 'Piped input' ]
|
||||
}
|
||||
|
||||
@test "container_run delegates env vars starting with DOCKER_" {
|
||||
DOCKER_key=value run container_run "$IMAGE" printenv DOCKER_key
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'value' ]
|
||||
}
|
||||
|
||||
@test "container_run doesn't delegate env var TZ" {
|
||||
TZ=UTC run container_run "$IMAGE" printenv TZ
|
||||
[ -z "$output" ]
|
||||
}
|
||||
|
||||
@test "container_run delegates env var SOURCE_DATE_EPOCH" {
|
||||
SOURCE_DATE_EPOCH=1562027497 run container_run "$IMAGE" printenv SOURCE_DATE_EPOCH
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = '1562027497' ]
|
||||
}
|
||||
|
||||
52
build/dobuild/tests/31_get_container_id.bats
Normal file
52
build/dobuild/tests/31_get_container_id.bats
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
build_and_run() {
|
||||
debug_trace "$DOCKER" build --rm --iidfile "$IDDFILE" --file "$DOCKERFILE" \
|
||||
--build-arg "DOCKER_VERSION=$DOCKER_VERSION" \
|
||||
--build-arg "REGISTRY_PREFIX=$REGISTRY_PREFIX" \
|
||||
"$PROJECTPATH" 1>&2
|
||||
|
||||
set -- "$(cat "$IDDFILE")" "$@"
|
||||
|
||||
debug_trace container_run "$@"
|
||||
}
|
||||
|
||||
setup() {
|
||||
PROJECTPATH="$(readlink -f "$BATS_TEST_DIRNAME/..")"
|
||||
BINPATH="$PROJECTPATH/bin"
|
||||
PATH="$BINPATH:$PATH"
|
||||
IDDFILE="$(mktemp --tmpdir="$BATS_TMPDIR" idd_XXXXXXXXXX.txt)"
|
||||
DOCKERFILE="$BATS_TEST_DIRNAME/get_container_id.dockerfile"
|
||||
|
||||
export PROJECTPATH
|
||||
export IDDFILE
|
||||
export DOCKERFILE
|
||||
}
|
||||
|
||||
teardown() {
|
||||
"$DOCKER" rmi "$(cat "$IDDFILE")"
|
||||
rm -f "$IDDFILE"
|
||||
}
|
||||
|
||||
@test "get_container_id has required dep docker" {
|
||||
"$DOCKER" --version
|
||||
echo "docker unreachable!?"
|
||||
echo "DOCKER_HOST=$DOCKER_HOST"
|
||||
"$DOCKER" info
|
||||
}
|
||||
|
||||
@test "get_container_id self-id within container" {
|
||||
ID="$(build_and_run ./get_container_id.sh)"
|
||||
[ -n "$ID" ]
|
||||
}
|
||||
37
build/dobuild/tests/31_shellcheck.bats
Normal file
37
build/dobuild/tests/31_shellcheck.bats
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
PROJECTPATH="$(readlink -f "$BATS_TEST_DIRNAME/..")"
|
||||
BINPATH="$PROJECTPATH/bin"
|
||||
PATH="$BINPATH:$PATH"
|
||||
|
||||
SHELLCHECK=( shellcheck --color=never --format=gcc -x )
|
||||
}
|
||||
|
||||
@test "shellcheck has required deps" {
|
||||
"${SHELLCHECK[@]}" --version
|
||||
}
|
||||
|
||||
@test "shellcheck run_tests" {
|
||||
"${SHELLCHECK[@]}" "$PROJECTPATH/run_tests"
|
||||
}
|
||||
|
||||
@test "shellcheck helper scripts" {
|
||||
find "$BINPATH" -type f -print0 | parallel --keep-order -0 "${SHELLCHECK[@]}" {}
|
||||
}
|
||||
|
||||
@test "shellcheck test helper scripts" {
|
||||
find "$BATS_TEST_DIRNAME" -type f -name '*.bash' -print0 | parallel --keep-order -0 "${SHELLCHECK[@]}" {}
|
||||
}
|
||||
|
||||
70
build/dobuild/tests/32_groovy3.bats
Normal file
70
build/dobuild/tests/32_groovy3.bats
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
PROJECTPATH="$(readlink -f "$BATS_TEST_DIRNAME/..")"
|
||||
BINPATH="$PROJECTPATH/bin"
|
||||
PATH="$BINPATH:$PATH"
|
||||
|
||||
GROOVY=( groovy3 )
|
||||
}
|
||||
|
||||
@test "groovy3 has required deps" {
|
||||
"${GROOVY[@]}" --version
|
||||
}
|
||||
|
||||
print_fixture_ymlslurper() {
|
||||
cat <<- EOF
|
||||
import groovy.yaml.YamlSlurper
|
||||
|
||||
def configYaml = '''\
|
||||
|---
|
||||
|application: "Sample App"
|
||||
|users:
|
||||
|- name: "mrhaki"
|
||||
| likes:
|
||||
| - Groovy
|
||||
| - Clojure
|
||||
| - Java
|
||||
|- name: "Hubert"
|
||||
| likes:
|
||||
| - Apples
|
||||
| - Bananas
|
||||
|connections:
|
||||
|- "WS1"
|
||||
|- "WS2"
|
||||
'''
|
||||
|
||||
// Parse the YAML.
|
||||
def config = new YamlSlurper().parseText(configYaml.stripMargin())
|
||||
|
||||
assert config.application == 'Sample App'
|
||||
|
||||
assert config.users.size() == 2
|
||||
assert config.users[0] == [name: 'mrhaki', likes: ['Groovy', 'Clojure', 'Java']]
|
||||
assert config.users[1] == [name: 'Hubert', likes: ['Apples', 'Bananas']]
|
||||
|
||||
assert config.connections == ['WS1', 'WS2']
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "groovy3 ymlslurper test" {
|
||||
run "${GROOVY[@]}" -e "$(print_fixture_ymlslurper)"
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -z "${lines[@]}" ]
|
||||
}
|
||||
|
||||
|
||||
|
||||
90
build/dobuild/tests/40_parse_make_targets.bats
Normal file
90
build/dobuild/tests/40_parse_make_targets.bats
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
BINPATH="$(readlink -f "$BATS_TEST_DIRNAME/../bin")"
|
||||
PATH="$BINPATH:$PATH"
|
||||
}
|
||||
|
||||
@test "parse_make_targets has required dep awk" {
|
||||
awk 'BEGIN {print "Hello from awk"}'
|
||||
}
|
||||
|
||||
@test "parse_make_targets has required dep grep" {
|
||||
echo 'hello' | grep -e 'hello'
|
||||
}
|
||||
|
||||
@test "parse_make_targets has required dep sort" {
|
||||
sort --version
|
||||
}
|
||||
|
||||
@test "parse_make_targets has required dep make" {
|
||||
make --version
|
||||
}
|
||||
|
||||
print_simple_makefile() {
|
||||
cat <<EOF
|
||||
.PHONY: default
|
||||
default: all
|
||||
.PHONY: all
|
||||
all:
|
||||
.PHONY: clean
|
||||
clean:
|
||||
EOF
|
||||
}
|
||||
|
||||
print_error_makefile() {
|
||||
cat <<EOF
|
||||
\$(error within Makefile)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "parse_make_targets should fail when used with invalid arguments" {
|
||||
run parse_make_targets.sh --unknown-make-option 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[ -n "$output" ]
|
||||
}
|
||||
|
||||
@test "parse_make_targets should fail when makefile contains errors" {
|
||||
run parse_make_targets.sh -f -< <(print_error_makefile)
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[ -n "$output" ]
|
||||
}
|
||||
|
||||
@test "parse_make_targets should parse simple makefile from stdin" {
|
||||
run parse_make_targets.sh -f -< <(print_simple_makefile)
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = 'all' ]
|
||||
[ "${lines[1]}" = 'clean' ]
|
||||
[ "${lines[2]}" = 'default' ]
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
}
|
||||
|
||||
@test "parse_make_targets should parse a more advanced makefile" {
|
||||
run parse_make_targets.sh -C "$BATS_TEST_DIRNAME/fixtures/make-gtest-example"
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = 'all' ]
|
||||
[ "${lines[1]}" = 'alltests' ]
|
||||
[ "${lines[2]}" = 'clean' ]
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
}
|
||||
|
||||
|
||||
230
build/dobuild/tests/40_parse_target_properties.bats
Normal file
230
build/dobuild/tests/40_parse_target_properties.bats
Normal file
@@ -0,0 +1,230 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
BINPATH="$(readlink -f "$BATS_TEST_DIRNAME/../bin")"
|
||||
PATH="$BINPATH:$PATH"
|
||||
HOST_ARCH="$(uname -m)"
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh has required deps" {
|
||||
sed --version
|
||||
paste --version
|
||||
uname --version
|
||||
cat --version
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh fails when called without target name" {
|
||||
run parse_target_properties.sh
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[ -n "$output" ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse shortest target name" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh app-id )
|
||||
|
||||
[ "${PROPERTIES[0]}" = "$HOST_ARCH" ]
|
||||
[ "${PROPERTIES[1]}" = "$HOST_ARCH" ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'app-id' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
[ "${PROPERTIES[7]}" = 'release' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse host-march and id target name" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh x86_64+builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'x86_64' ]
|
||||
[ "${PROPERTIES[1]}" = 'x86_64' ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh x86_64 builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'x86_64' ]
|
||||
[ "${PROPERTIES[1]}" = 'x86_64' ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse longest target name" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386+arm32v7-alpine@3.9-none-eabihf+builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'alpine' ]
|
||||
[ "${PROPERTIES[3]}" = 'none' ]
|
||||
[ "${PROPERTIES[4]}" = 'eabihf' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = '3.9' ]
|
||||
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386 arm32v7-alpine@3.9-none-eabihf builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'alpine' ]
|
||||
[ "${PROPERTIES[3]}" = 'none' ]
|
||||
[ "${PROPERTIES[4]}" = 'eabihf' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = '3.9' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse distribution version containing unescaped special character [@]" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386+arm32v7-alpine@3.9@345+builder-template~@y )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'alpine' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template@y' ]
|
||||
[ "${PROPERTIES[6]}" = '3.9@345' ]
|
||||
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386 arm32v7-alpine@3.9@345 builder-template~@y )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'alpine' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template@y' ]
|
||||
[ "${PROPERTIES[6]}" = '3.9@345' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse target abi containing unescaped special character [-]" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh arm32v7-alpine@3.9-linux-gnu-x+builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'alpine' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu-x' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = '3.9' ]
|
||||
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh arm32v7-alpine@3.9-linux-gnu-x builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'alpine' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu-x' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = '3.9' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse application id containing unescaped special characters [-]" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386+builder-template@y-z )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'i386' ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
[ "${PROPERTIES[7]}" = 'y-z' ]
|
||||
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386 builder-template@y-z )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'i386' ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
[ "${PROPERTIES[7]}" = 'y-z' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse application id containing unescaped special character [+], when host arch is given" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh + )
|
||||
|
||||
[ "${PROPERTIES[0]}" = "$HOST_ARCH" ]
|
||||
[ "${PROPERTIES[1]}" = "$HOST_ARCH" ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = '+' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386+arm32v7+builder-template@x+y-z )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
[ "${PROPERTIES[7]}" = 'x+y-z' ]
|
||||
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh i386 arm32v7 builder-template@x y-z )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'i386' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
[ "${PROPERTIES[7]}" = 'x+y-z' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse escaped chars [+|\\s] in target name" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh 'x86~+arm32~ ~~-x-alpine~+app' )
|
||||
|
||||
[ "${PROPERTIES[0]}" = "$HOST_ARCH" ]
|
||||
[ "${PROPERTIES[1]}" = "$HOST_ARCH" ]
|
||||
[ "${PROPERTIES[2]}" = 'unknown' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu' ]
|
||||
[ "${PROPERTIES[5]}" = 'x86+arm32 ~-x-alpine+app' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse escaped char [@] in target name" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh arm32v7-alpine~@3.9-linux-gnu-x+builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'alpine@3.9' ]
|
||||
[ "${PROPERTIES[3]}" = 'linux' ]
|
||||
[ "${PROPERTIES[4]}" = 'gnu-x' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
}
|
||||
|
||||
@test "parse_target_properties.sh should parse escaped char [-] in target name" {
|
||||
mapfile -t PROPERTIES < <( parse_target_properties.sh arm32v7-linaro~-gcc-none-eabihf+builder-template )
|
||||
|
||||
[ "${PROPERTIES[0]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[1]}" = 'arm32v7' ]
|
||||
[ "${PROPERTIES[2]}" = 'linaro-gcc' ]
|
||||
[ "${PROPERTIES[3]}" = 'none' ]
|
||||
[ "${PROPERTIES[4]}" = 'eabihf' ]
|
||||
[ "${PROPERTIES[5]}" = 'builder-template' ]
|
||||
[ "${PROPERTIES[6]}" = 'latest' ]
|
||||
|
||||
}
|
||||
|
||||
310
build/dobuild/tests/41_dobuild_opts.bats
Normal file
310
build/dobuild/tests/41_dobuild_opts.bats
Normal file
@@ -0,0 +1,310 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
BINPATH="$(readlink -f "$BATS_TEST_DIRNAME/../bin")"
|
||||
PATH="$BINPATH:$PATH"
|
||||
TEMP="$(mktemp --directory --tmpdir="$BATS_TMPDIR" dobuild_XXXXXXXXXX)"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf "$TEMP"
|
||||
}
|
||||
|
||||
@test "dobuild has required dep find" {
|
||||
find --version
|
||||
}
|
||||
|
||||
@test "dobuild has required dep dirname" {
|
||||
dirname --version
|
||||
}
|
||||
|
||||
@test "dobuild has required dep mkdir" {
|
||||
mkdir --version
|
||||
}
|
||||
|
||||
@test "dobuild has required dep grep" {
|
||||
grep --version
|
||||
}
|
||||
|
||||
@test "dobuild has required dep sed" {
|
||||
sed --version
|
||||
}
|
||||
|
||||
@test "dobuild should fail when -f, --file or --makefile argument is empty" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -f 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"-f" requires a non-empty option argument' ]]
|
||||
|
||||
run dobuild --file 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--file" requires a non-empty option argument' ]]
|
||||
|
||||
run dobuild --file= 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--file=" requires a non-empty option argument' ]]
|
||||
|
||||
run dobuild --makefile 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--makefile" requires a non-empty option argument' ]]
|
||||
|
||||
run dobuild --makefile= 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--makefile=" requires a non-empty option argument' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should pass -f, --file or --makefile argument to make" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -f Makefile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ '-f Makefile' ]]
|
||||
|
||||
run dobuild --file Makefile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ '--file Makefile' ]]
|
||||
|
||||
run dobuild --file=Makefile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ '--file=Makefile' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should pass all -f, --file or --makefile arguments to make and use first to determine project kind" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -f Makefile -f other.mk
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ '-f Makefile -f other.mk' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should fail when -C, --directory argument is empty" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -C 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"-C" requires a non-empty option argument' ]]
|
||||
|
||||
run dobuild --directory 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--directory" requires a non-empty option argument' ]]
|
||||
|
||||
run dobuild --directory= 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--directory=" requires a non-empty option argument' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should not pass -C, --directory arguments to make" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -C "$TEMP" -f Makefile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ "-C $TEMP" ]]
|
||||
|
||||
run dobuild --directory "$TEMP" -f Makefile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ "--directory $TEMP" ]]
|
||||
|
||||
run dobuild --directory="$TEMP" -f Makefile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ "--directory=$TEMP" ]]
|
||||
}
|
||||
|
||||
@test "dobuild should fail when directory denoted by -C, --directory does not exist" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -C non-existent -f Makefile 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "can't cd to non-existent" ]]
|
||||
|
||||
run dobuild --directory non-existent -f Makefile 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "can't cd to non-existent" ]]
|
||||
|
||||
run dobuild --directory=non-existent -f Makefile 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "can't cd to non-existent" ]]
|
||||
}
|
||||
|
||||
@test "dobuild should fail when --image argument is empty" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild --image 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--image" requires a non-empty option argument' ]]
|
||||
|
||||
run dobuild --image= 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ '"--image=" requires a non-empty option argument' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should print warning when --dockerfile argument is empty and fail while project kind is unknown" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -C "$TEMP" --dockerfile 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ 'warning: "--dockerfile" ignored, requires a non-empty option argument' ]]
|
||||
[[ "$output" =~ 'error: unknown project kind' ]]
|
||||
|
||||
run dobuild -C "$TEMP" --dockerfile= 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ 'warning: "--dockerfile=" ignored, requires a non-empty option argument' ]]
|
||||
[[ "$output" =~ 'error: unknown project kind' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should pass --dockerfile argument to make as DOCKERFILE variable" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -f Makefile --dockerfile=Dockerfile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'DOCKERFILE=Dockerfile' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should try to find dockerfile by FILTER in project by default and fails while no exact match can be found" {
|
||||
export MAKE='echo'
|
||||
|
||||
touch "$TEMP/Dockerfile"
|
||||
touch "$TEMP/arm32v7-alpine-x.dockerfile"
|
||||
touch "$TEMP/x86_64-alpine-x.dockerfile"
|
||||
|
||||
run dobuild -C "$TEMP" -f Makefile 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ 'more than one match found for *.dockerfile in . using filter [^-]*-[^.]*' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should find exact match for dockerfile using MARCH and DISTRIB" {
|
||||
export MAKE='echo'
|
||||
|
||||
touch "$TEMP/Dockerfile"
|
||||
touch "$TEMP/arm32v7-alpine-x.dockerfile"
|
||||
touch "$TEMP/x86_64-alpine-x.dockerfile"
|
||||
touch "$TEMP/arm32v7-ubuntu-x.dockerfile"
|
||||
touch "$TEMP/x86_64-ubuntu-x.dockerfile"
|
||||
|
||||
run dobuild -C "$TEMP" -f Makefile MARCH=arm32v7 DISTRIB=ubuntu 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'DOCKERFILE=./arm32v7-ubuntu-x.dockerfile' ]]
|
||||
|
||||
run dobuild -C "$TEMP" -f Makefile MARCH=arm32v7 DISTRIB=alpine 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'DOCKERFILE=./arm32v7-alpine-x.dockerfile' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should find exact match for dockerfile using FILTER" {
|
||||
export MAKE='echo'
|
||||
|
||||
touch "$TEMP/Dockerfile"
|
||||
touch "$TEMP/arm32v7-alpine-x.dockerfile"
|
||||
touch "$TEMP/x86_64-alpine-x.dockerfile"
|
||||
touch "$TEMP/arm32v7-ubuntu-x.dockerfile"
|
||||
touch "$TEMP/x86_64-ubuntu-x.dockerfile"
|
||||
|
||||
run dobuild -C "$TEMP" -f Makefile --filter 'arm.\?.\?v7-alpine-x' 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'DOCKERFILE=./arm32v7-alpine-x.dockerfile' ]]
|
||||
[[ "$output" =~ 'FILTER=arm.\?.\?v7-alpine-x' ]]
|
||||
|
||||
run dobuild -C "$TEMP" -f Makefile 'FILTER=arm.\?.\?v7-alpine-x' 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'DOCKERFILE=./arm32v7-alpine-x.dockerfile' ]]
|
||||
[[ "$output" =~ 'FILTER=arm.\?.\?v7-alpine-x' ]]
|
||||
}
|
||||
|
||||
@test "dobuild should fallback to Dockerfile in project by default" {
|
||||
export MAKE='echo'
|
||||
|
||||
touch "$TEMP/Dockerfile"
|
||||
|
||||
run dobuild -C "$TEMP" -f Makefile
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "DOCKERFILE=./Dockerfile" ]]
|
||||
}
|
||||
|
||||
@test "dobuild should print warning when --filter argument is empty and fail while project kind is unknown" {
|
||||
export MAKE='echo'
|
||||
|
||||
run dobuild -C "$TEMP" --filter 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ 'warning: "--filter" ignored, requires a non-empty option argument' ]]
|
||||
[[ "$output" =~ 'error: unknown project kind' ]]
|
||||
|
||||
run dobuild -C "$TEMP" --filter= 2>&1
|
||||
|
||||
echo "$output"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ 'warning: "--filter=" ignored, requires a non-empty option argument' ]]
|
||||
[[ "$output" =~ 'error: unknown project kind' ]]
|
||||
}
|
||||
|
||||
|
||||
554
build/dobuild/tests/50_defaults_mk.bats
Normal file
554
build/dobuild/tests/50_defaults_mk.bats
Normal file
@@ -0,0 +1,554 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
PROJECTPATH="$(readlink -f "$BATS_TEST_DIRNAME/..")"
|
||||
MAKE=("make" --no-print-directory -C "$PROJECTPATH" -f defaults.mk -f "$BATS_TEST_DIRNAME/test_helper.mk")
|
||||
VERSIONFILE="$(mktemp --tmpdir="$BATS_TMPDIR" version_XXXXXXXXXX.txt)"
|
||||
|
||||
export DOBUILD_PROJECTVERSIONFILE="$VERSIONFILE"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -f "$VERSIONFILE"
|
||||
}
|
||||
|
||||
@test "defaults_mk has required deps" {
|
||||
"${MAKE[@]}" --version
|
||||
}
|
||||
|
||||
@test "defaults_mk has required makefile deps" {
|
||||
"${MAKE[@]}" testhelper-print-MAKEFILE_DEPS | sort -u | parallel --keep-order command -V
|
||||
}
|
||||
|
||||
@test "defaults_mk can be included multiple times" {
|
||||
run "${MAKE[@]}" -f defaults.mk 2>&1
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done' ]]
|
||||
}
|
||||
|
||||
print_fixture_or() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call or,)
|
||||
VALUES += 2_\$(call or,a,b)
|
||||
VALUES += 3_\$(call or,,,,b)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function or" {
|
||||
run eval 'print_fixture_or | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_" ]
|
||||
[ "${lines[1]}" = "2_a" ]
|
||||
[ "${lines[2]}" = "3_b" ]
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
}
|
||||
|
||||
print_fixture_lastword() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call lastword,)
|
||||
VALUES += 2_\$(call lastword,0 1)
|
||||
VALUES += 3_\$(call lastword,1 2 3)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function lastword" {
|
||||
run eval 'print_fixture_lastword | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_" ]
|
||||
[ "${lines[1]}" = "2_1" ]
|
||||
[ "${lines[2]}" = "3_3" ]
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
}
|
||||
|
||||
print_fixture_eq_s() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call eq_s,1,1)
|
||||
VALUES += 2_\$(call eq_s,1,2)
|
||||
VALUES += 3_\$(call eq_s,text,text)
|
||||
VALUES += 4_\$(call eq_s,text,other)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function eq_s" {
|
||||
run eval 'print_fixture_eq_s | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_1" ]
|
||||
[ "${lines[1]}" = "2_" ]
|
||||
[ "${lines[2]}" = "3_text" ]
|
||||
[ "${lines[3]}" = "4_" ]
|
||||
[ "${#lines[@]}" -eq 4 ]
|
||||
}
|
||||
|
||||
print_fixture_tail() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call tail,)
|
||||
VALUES += 2_\$(call tail,1)
|
||||
VALUES += 3_\$(call tail,1 42)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function tail" {
|
||||
run eval 'print_fixture_tail | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_" ]
|
||||
[ "${lines[1]}" = "2_" ]
|
||||
[ "${lines[2]}" = "3_42" ]
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
}
|
||||
|
||||
print_fixture_eq_each() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call eq_each,1,1,eq_s)
|
||||
VALUES += 2_\$(call eq_each,1,2,eq_s)
|
||||
VALUES += 3_\$(call eq_each,text,text,eq_s)
|
||||
VALUES += 4_\$(call eq_each,text,other,eq_s)
|
||||
VALUES += 5_\$(call eq_each,a b,a b,eq_s)
|
||||
VALUES += 6_\$(call eq_each,a b,a c,eq_s)
|
||||
VALUES += 7_\$(call eq_each,a b,a,eq_s)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function eq_each" {
|
||||
run eval 'print_fixture_eq_each | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_1" ]
|
||||
[ "${lines[1]}" = "2_" ]
|
||||
[ "${lines[2]}" = "3_1" ]
|
||||
[ "${lines[3]}" = "4_" ]
|
||||
[ "${lines[4]}" = "5_1" ]
|
||||
[ "${lines[5]}" = "6_" ]
|
||||
[ "${lines[6]}" = "7_" ]
|
||||
[ "${#lines[@]}" -eq 7 ]
|
||||
}
|
||||
|
||||
print_fixture_eq() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call eq,1,1,eq_s)
|
||||
VALUES += 2_\$(call eq,1,2)
|
||||
VALUES += 3_\$(call eq,text,text)
|
||||
VALUES += 4_\$(call eq,text,other)
|
||||
VALUES += 5_\$(call eq,a b,a b)
|
||||
VALUES += 6_\$(call eq,a b,a c)
|
||||
VALUES += 7_\$(call eq,a b,a)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function eq" {
|
||||
run eval 'print_fixture_eq | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_1" ]
|
||||
[ "${lines[1]}" = "2_" ]
|
||||
[ "${lines[2]}" = "3_1" ]
|
||||
[ "${lines[3]}" = "4_" ]
|
||||
[ "${lines[4]}" = "5_1" ]
|
||||
[ "${lines[5]}" = "6_" ]
|
||||
[ "${lines[6]}" = "7_" ]
|
||||
[ "${#lines[@]}" -eq 7 ]
|
||||
}
|
||||
|
||||
print_fixture_target_properties_matches() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call target_properties_matches,1,1)
|
||||
VALUES += 2_\$(call target_properties_matches,1,2)
|
||||
VALUES += 3_\$(call target_properties_matches,text,text)
|
||||
VALUES += 4_\$(call target_properties_matches,text,other)
|
||||
VALUES += 5_\$(call target_properties_matches,%,text)
|
||||
VALUES += 6_\$(call target_properties_matches,text,%)
|
||||
VALUES += 7_\$(call target_properties_matches,a % c,a b c)
|
||||
VALUES += 8_\$(call target_properties_matches,a d %,a b c)
|
||||
VALUES += 9_\$(call target_properties_matches,a d,a d c)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function target_properties_matches" {
|
||||
run eval 'print_fixture_target_properties_matches | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_1" ]
|
||||
[ "${lines[1]}" = "2_" ]
|
||||
[ "${lines[2]}" = "3_1" ]
|
||||
[ "${lines[3]}" = "4_" ]
|
||||
[ "${lines[4]}" = "5_1" ]
|
||||
[ "${lines[5]}" = "6_" ]
|
||||
[ "${lines[6]}" = "7_1" ]
|
||||
[ "${lines[7]}" = "8_" ]
|
||||
[ "${lines[8]}" = "9_" ]
|
||||
[ "${#lines[@]}" -eq 9 ]
|
||||
}
|
||||
|
||||
print_fixture_target_matches() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call target_matches,x86_64+builder-template,x86_64 x86_64 unknown linux gnu builder-template latest release)
|
||||
VALUES += 2_\$(call target_matches,i386+arm32v7-alpine@3.9-none-eabihf+builder-template,i386 arm32v7 alpine none eabihf builder-template 3.9 release)
|
||||
VALUES += 3_\$(call target_matches,arm32v7-alpine@3.9-none-eabihf+builder-template,arm32v7 arm32v7 alpine % % % % %)
|
||||
VALUES += 4_\$(call target_matches,arm32v7-alpine@3.9-none-eabihf+builder-template,% arm32v7 alpine % % % % %)
|
||||
VALUES += 5_\$(call target_matches,i386+arm32v7-alpine@3.9-none-eabihf+builder-template,i386 arm32v7 ubuntu % % % % %)
|
||||
VALUES += 6_\$(call target_matches,i386+arm32v7-alpine@3.9-none-eabihf+builder-template@debug,i386 arm32v7 alpine % % % % debug)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function target_matches" {
|
||||
run eval 'print_fixture_target_matches | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_1" ]
|
||||
[ "${lines[1]}" = "2_1" ]
|
||||
[ "${lines[2]}" = "3_1" ]
|
||||
[ "${lines[3]}" = "4_1" ]
|
||||
[ "${lines[4]}" = "5_" ]
|
||||
[ "${lines[5]}" = "6_1" ]
|
||||
[ "${#lines[@]}" -eq 6 ]
|
||||
}
|
||||
|
||||
print_fixture_target_filter() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call target_filter,x86_64+x86_64-unknown@latest-linux-gnu+builder-template,x86_64+builder-template)
|
||||
VALUES += 2_\$(call target_filter,i386+arm32v7-alpine@3.9-none-eabihf+builder-template,i386+arm32v7-alpine@3.9-none-eabihf+builder-template)
|
||||
VALUES += 3_\$(call target_filter,arm32v7+arm32v7-alpine@%-%-%+%,arm32v7-alpine@3.9-none-eabihf+builder-template)
|
||||
VALUES += 4_\$(call target_filter,%+arm32v7-alpine@%-%-%+%,arm32v7-alpine@3.9-none-eabihf+builder-template)
|
||||
VALUES += 5_\$(call target_filter,i386+arm32v7-ubuntu@%-%-%+%,i386+arm32v7-alpine@3.9-none-eabihf+builder-template)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function target_filter" {
|
||||
run eval 'print_fixture_target_filter | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_x86_64+builder-template" ]
|
||||
[ "${lines[1]}" = "2_i386+arm32v7-alpine@3.9-none-eabihf+builder-template" ]
|
||||
[ "${lines[2]}" = "3_arm32v7-alpine@3.9-none-eabihf+builder-template" ]
|
||||
[ "${lines[3]}" = "4_arm32v7-alpine@3.9-none-eabihf+builder-template" ]
|
||||
[ "${lines[4]}" = "5_" ]
|
||||
[ "${#lines[@]}" -eq 5 ]
|
||||
}
|
||||
|
||||
|
||||
print_fixture_compare() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call compare, 1, 2)
|
||||
VALUES += 2_\$(call compare,-1,-2)
|
||||
VALUES += 3_\$(call compare, 1, 1)
|
||||
VALUES += 4_\$(call compare,-1, 2)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function compare" {
|
||||
run eval 'print_fixture_compare | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_-1" ]
|
||||
[ "${lines[1]}" = "2_1" ]
|
||||
[ "${lines[2]}" = "3_0" ]
|
||||
[ "${lines[3]}" = "4_-3" ]
|
||||
[ "${#lines[@]}" -eq 4 ]
|
||||
}
|
||||
|
||||
print_fixture_lt() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call lt, 1, 2)
|
||||
VALUES += 2_\$(call lt,-1,-2)
|
||||
VALUES += 3_\$(call lt, 1, 1)
|
||||
VALUES += 4_\$(call lt,-1, 2)
|
||||
VALUES += 5_\$(call lt, 4, 2)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function lt" {
|
||||
run eval 'print_fixture_lt | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_1" ]
|
||||
[ "${lines[1]}" = "2_" ]
|
||||
[ "${lines[2]}" = "3_" ]
|
||||
[ "${lines[3]}" = "4_1" ]
|
||||
[ "${lines[4]}" = "5_" ]
|
||||
[ "${#lines[@]}" -eq 5 ]
|
||||
}
|
||||
|
||||
print_fixture_gt() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call gt, 1, 2)
|
||||
VALUES += 2_\$(call gt,-1,-2)
|
||||
VALUES += 3_\$(call gt, 1, 1)
|
||||
VALUES += 4_\$(call gt,-1, 2)
|
||||
VALUES += 5_\$(call gt, 4, 2)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function gt" {
|
||||
run eval 'print_fixture_gt | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_" ]
|
||||
[ "${lines[1]}" = "2_1" ]
|
||||
[ "${lines[2]}" = "3_" ]
|
||||
[ "${lines[3]}" = "4_" ]
|
||||
[ "${lines[4]}" = "5_1" ]
|
||||
[ "${#lines[@]}" -eq 5 ]
|
||||
}
|
||||
|
||||
print_fixture_ge() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call ge, 1, 2)
|
||||
VALUES += 2_\$(call ge,-1,-2)
|
||||
VALUES += 3_\$(call ge, 1, 1)
|
||||
VALUES += 4_\$(call ge,-1, 2)
|
||||
VALUES += 5_\$(call ge, 4, 2)
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function ge" {
|
||||
run eval 'print_fixture_ge | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_" ]
|
||||
[ "${lines[1]}" = "2_1" ]
|
||||
[ "${lines[2]}" = "3_1" ]
|
||||
[ "${lines[3]}" = "4_" ]
|
||||
[ "${lines[4]}" = "5_1" ]
|
||||
[ "${#lines[@]}" -eq 5 ]
|
||||
}
|
||||
|
||||
print_fixture_ge_version() {
|
||||
cat <<EOF
|
||||
VALUES += 1_\$(call ge_version, 3, 1)
|
||||
VALUES += 2_\$(call ge_version, 1, 2)
|
||||
VALUES += 3_\$(call ge_version, 1, 1)
|
||||
VALUES += 4_\$(call ge_version, 1 1, 2 0)
|
||||
VALUES += 5_\$(call ge_version, 1 2, 1 0)
|
||||
VALUES += 6_\$(call ge_version, 1 1, 1 2)
|
||||
VALUES += 7_\$(call ge_version, 1 1, 2 3)
|
||||
VALUES += 8_\$(call ge_version, 1 1, 1)
|
||||
VALUES += 9_\$(call ge_version, 1 1 1, 1)
|
||||
VALUES += 10_\$(call ge_version, 1, 1 1 1)
|
||||
VALUES += 11_\$(call ge_version, 1 2, 1 1 1)
|
||||
VALUES += 12_\$(call ge_version, 1 2 1, 1 2 0)
|
||||
VALUES += 13_\$(call ge_version, , 1)
|
||||
VALUES += 14_\$(call ge_version, 2, )
|
||||
VALUES += 15_\$(call ge_version, , )
|
||||
EOF
|
||||
}
|
||||
|
||||
@test "defaults_mk test function ge_version" {
|
||||
run eval 'print_fixture_ge_version | "${MAKE[@]}" -f - testhelper-print-VALUES'
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "1_1" ]
|
||||
[ "${lines[1]}" = "2_" ]
|
||||
[ "${lines[2]}" = "3_1" ]
|
||||
[ "${lines[3]}" = "4_" ]
|
||||
[ "${lines[4]}" = "5_1" ]
|
||||
[ "${lines[5]}" = "6_" ]
|
||||
[ "${lines[6]}" = "7_" ]
|
||||
[ "${lines[7]}" = "8_1" ]
|
||||
[ "${lines[8]}" = "9_1" ]
|
||||
[ "${lines[9]}" = "10_" ]
|
||||
[ "${lines[10]}" = "11_1" ]
|
||||
[ "${lines[11]}" = "12_1" ]
|
||||
[ "${lines[12]}" = "13_" ]
|
||||
[ "${lines[13]}" = "14_1" ]
|
||||
[ "${lines[14]}" = "15_1" ]
|
||||
[ "${#lines[@]}" -eq 15 ]
|
||||
}
|
||||
|
||||
@test "defaults_mk PROJECTNAME equals directory of first loaded makefile by default and can't be overridden accidentally" {
|
||||
EXPECTED="$(basename "$PROJECTPATH")"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-PROJECTNAME)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
|
||||
export PROJECTNAME='myproject'
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-PROJECTNAME)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk PROJECTNAME can be overridden by env var DOBUILD_PROJECTNAME" {
|
||||
export DOBUILD_PROJECTNAME='myproject'
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-PROJECTNAME)"
|
||||
echo "$VALUE"
|
||||
[ "$VALUE" = "myproject" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk PROJECTDIR equals directory of first loaded makefile by default and can't be overridden accidentally" {
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-PROJECTDIR)"
|
||||
echo "$VALUE != ."
|
||||
[ "$VALUE" = '.' ]
|
||||
|
||||
export PROJECTDIR='myproject'
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-PROJECTDIR)"
|
||||
echo "$VALUE != ."
|
||||
[ "$VALUE" = '.' ]
|
||||
}
|
||||
|
||||
@test "defaults_mk PROJECTDIR can be overridden by env var DOBUILD_PROJECTDIR" {
|
||||
export DOBUILD_PROJECTDIR='myproject'
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-PROJECTDIR)"
|
||||
echo "$VALUE"
|
||||
[ "$VALUE" = "myproject" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk USERID equals UID by default and can't be overridden accidentally" {
|
||||
EXPECTED="$(id -u)"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-USERID)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
|
||||
export USERID='an_user'
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-USERID)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk USERID can be overridden by env var DOBUILD_USERID" {
|
||||
EXPECTED="1234"
|
||||
export DOBUILD_USERID="$EXPECTED"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-USERID)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk VERSION is empty when no version file exists" {
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-VERSION VERSIONFILE='')"
|
||||
echo "$VALUE"
|
||||
[ -z "$VALUE" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk VERSION equals version in provided file" {
|
||||
EXPECTED='99.99.99'
|
||||
echo "$EXPECTED" > "$VERSIONFILE"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-VERSION)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk HOST_CONTAINER can be overridden by env var DOBUILD_HOSTCONTAINER" {
|
||||
EXPECTED="1234"
|
||||
export DOBUILD_HOSTCONTAINER="$EXPECTED"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-HOST_CONTAINER)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk SOURCE_DATE_EPOCH is number" {
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-SOURCE_DATE_EPOCH)"
|
||||
[ "$VALUE" -ge 0 ]
|
||||
}
|
||||
|
||||
@test "defaults_mk SOURCE_DATE_EPOCH can be overridden" {
|
||||
EXPECTED="1234"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-SOURCE_DATE_EPOCH SOURCE_DATE_EPOCH="$EXPECTED")"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk BUILDTIME is not empty" {
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-BUILDTIME)"
|
||||
[ -n "$VALUE" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk VERBOSE is off by default and can be overridden by env var" {
|
||||
VALUE="$("${MAKE[@]}" testhelper-default-silent)"
|
||||
echo "$VALUE"
|
||||
[ -z "$VALUE" ]
|
||||
|
||||
export VERBOSE=1
|
||||
VALUE="$("${MAKE[@]}" testhelper-default-silent)"
|
||||
echo "$VALUE"
|
||||
[ "$VALUE" = 'true' ]
|
||||
}
|
||||
|
||||
@test "defaults_mk JOBSLOTS defaults to system available processors" {
|
||||
EXPECTED="$(nproc)"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-JOBSLOTS)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" -eq "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk JOBSLOTS defaults to system available processors when make called recursive without -j" {
|
||||
EXPECTED="$(nproc)"
|
||||
VALUE="$("${MAKE[@]}" testhelper-recursive-print-JOBSLOTS)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" -eq "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk JOBSLOTS defaults to system available processors when make called recursive with unlimited job slots" {
|
||||
EXPECTED="$(nproc)"
|
||||
VALUE="$("${MAKE[@]}" -j testhelper-recursive-print-JOBSLOTS)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" -eq "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk JOBSLOTS defaults to 2 when make called recursive with limited job slots" {
|
||||
EXPECTED="2"
|
||||
VALUE="$("${MAKE[@]}" -j10 testhelper-recursive-print-JOBSLOTS)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" -eq "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk JOBSLOTS should be equal to last make command line argument" {
|
||||
VALUE="$("${MAKE[@]}" -j10 -j 42 testhelper-print-JOBSLOTS)"
|
||||
echo "$VALUE != 42"
|
||||
[ "$VALUE" -eq "42" ]
|
||||
|
||||
VALUE="$("${MAKE[@]}" -j14 testhelper-print-JOBSLOTS)"
|
||||
echo "$VALUE != 14"
|
||||
[ "$VALUE" -eq "14" ]
|
||||
|
||||
VALUE="$("${MAKE[@]}" -j11 testhelper-print-JOBSLOTS)"
|
||||
echo "$VALUE != 11"
|
||||
[ "$VALUE" -eq "11" ]
|
||||
|
||||
VALUE="$("${MAKE[@]}" --jobs 11 --jobs 10 testhelper-print-JOBSLOTS)"
|
||||
echo "$VALUE != 10"
|
||||
[ "$VALUE" -eq "10" ]
|
||||
|
||||
VALUE="$("${MAKE[@]}" -j10 --jobs=88 testhelper-print-JOBSLOTS)"
|
||||
echo "$VALUE != 88"
|
||||
[ "$VALUE" -eq "88" ]
|
||||
}
|
||||
|
||||
@test "defaults_mk MAKE_VERSION should be greater or equal to 3.81 warning" {
|
||||
run "${MAKE[@]}" make_version=4.1 testhelper-print-EXPECTATIONS 2>&1
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "Using old make version" ]]
|
||||
|
||||
run "${MAKE[@]}" make_version=3.80 testhelper-print-EXPECTATIONS 2>&1
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Using old make version" ]]
|
||||
}
|
||||
|
||||
237
build/dobuild/tests/60_standardrules_mk.bats
Normal file
237
build/dobuild/tests/60_standardrules_mk.bats
Normal file
@@ -0,0 +1,237 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
PROJECTPATH="$(readlink -f "$BATS_TEST_DIRNAME/..")"
|
||||
BINPATH="$PROJECTPATH/bin"
|
||||
PATH="$BINPATH:$PATH"
|
||||
OUTDIR="$(mktemp --directory --tmpdir="$BATS_TMPDIR" standardrules_XXXXXXXXXX)"
|
||||
MAKE=("make" --no-print-directory -C "$PROJECTPATH" -f standardrules.mk -f "$BATS_TEST_DIRNAME/test_helper.mk")
|
||||
|
||||
export DOBUILD_OUTDIR="$OUTDIR"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf "$OUTDIR"
|
||||
}
|
||||
|
||||
has_required_version() {
|
||||
local major=${1:-0}
|
||||
local minor=${2:-0}
|
||||
local bugfix=${3:-0}
|
||||
|
||||
set -- $(sed -n -e 's/.* Make \([0-9]\+\)[.]\([0-9]\+\)\([.]\([0-9]\+\)\)\?/\1 \2 \4/p')
|
||||
|
||||
if [ "$1" -gt "$major" ]; then
|
||||
return 0
|
||||
fi
|
||||
if [ "$1" -lt "$major" ]; then
|
||||
return -1
|
||||
fi
|
||||
|
||||
if [ "$2" -gt "$minor" ]; then
|
||||
return 0
|
||||
fi
|
||||
if [ "$2" -lt "$minor" ]; then
|
||||
return -2
|
||||
fi
|
||||
|
||||
if [ "${3:-0}" -ge "$bugfix" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return -3
|
||||
}
|
||||
|
||||
make_has_required_version() {
|
||||
"${MAKE[@]}" --version | has_required_version "$@"
|
||||
}
|
||||
|
||||
@test "standardrules_mk has required deps" {
|
||||
"${MAKE[@]}" --version
|
||||
}
|
||||
|
||||
@test "standardrules_mk has required makefile deps" {
|
||||
"${MAKE[@]}" testhelper-print-MAKEFILE_DEPS | sort -u | parallel --keep-order command -V
|
||||
}
|
||||
|
||||
@test "standardrules_mk PROJECTDIR should not contain whitespace" {
|
||||
run "${MAKE[@]}" PROJECTDIR='my project'
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "${lines[@]}" =~ "Project directory PROJECTDIR='my project' should not contain whitespaces" ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk DOBUILDDIR should not contain whitespace" {
|
||||
run "${MAKE[@]}" DOBUILDDIR='my scriptdir'
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "${lines[@]}" =~ "Script directory DOBUILDDIR='my scriptdir' should not contain whitespaces" ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk OUTDIRS should not contain PROJECTDIR" {
|
||||
run "${MAKE[@]}" PROJECTDIR="$PROJECTPATH" OUTDIR='.'
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "${lines[@]}" =~ "assertion failed: Project location PROJECTDIR" ]]
|
||||
[[ "${lines[@]}" =~ "should not point to one of the output locations" ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk all targets are tested" {
|
||||
run "${MAKE[@]}" print-targets 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = 'all' ]
|
||||
[ "${lines[1]}" = 'check' ]
|
||||
[ "${lines[2]}" = 'clean' ]
|
||||
[ "${lines[3]}" = 'dist' ]
|
||||
[ "${lines[4]}" = 'distclean' ]
|
||||
[ "${lines[5]}" = 'install' ]
|
||||
[ "${lines[6]}" = 'lint' ]
|
||||
[ "${lines[7]}" = 'memcheck' ]
|
||||
[ "${lines[8]}" = 'prepare' ]
|
||||
[ "${lines[9]}" = 'print-targets' ]
|
||||
[ "${lines[10]}" = 'run' ]
|
||||
# do not forget to add a test :)
|
||||
[ "${#lines[@]}" -ge 11 ]
|
||||
}
|
||||
|
||||
@test "standardrules_mk should run default target 'all' by default" {
|
||||
run "${MAKE[@]}" 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"all'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns success when empty check target is triggered" {
|
||||
run "${MAKE[@]}" check 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"check'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns success when empty clean target is triggered" {
|
||||
run "${MAKE[@]}" clean 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"clean'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns success when empty distclean target is triggered" {
|
||||
run "${MAKE[@]}" distclean 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"distclean'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns success when empty prepare target is triggered " {
|
||||
run "${MAKE[@]}" prepare 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"prepare'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns success when empty lint target is triggered" {
|
||||
run "${MAKE[@]}" lint 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"lint'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns success when empty memcheck target is triggered" {
|
||||
run "${MAKE[@]}" memcheck 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"memcheck'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns success when empty run target is triggered" {
|
||||
run "${MAKE[@]}" run 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ 'make: Nothing to be done for '[\`|\']"run'." ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk returns error when makefile dependency are unsatisfied" {
|
||||
run "${MAKE[@]}" MAKEFILE_DEPS='not-found1 not-found2 cat' not-found1 2>&1
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "${lines[@]}" =~ "Required commands not-found1 not-found2 not found; install appropriate packages" ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk should print PROJECTNAME when target triggered" {
|
||||
EXPECTED="$(basename "$PROJECTPATH")"
|
||||
VALUE="$("${MAKE[@]}" debug-print-PROJECTNAME)"
|
||||
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" = "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "standardrules_mk EXTERNPARALLEL should default to 1 when make called recursive with limited job slots" {
|
||||
EXPECTED="1"
|
||||
VALUE="$("${MAKE[@]}" -j10 testhelper-recursive-print-EXTERNPARALLEL)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" -eq "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "standardrules_mk INTERNPARALLEL should default to 2 when make called recursive with limited job slots" {
|
||||
EXPECTED="2"
|
||||
VALUE="$("${MAKE[@]}" -j10 testhelper-recursive-print-INTERNPARALLEL)"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" -eq "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "standardrules_mk EXTERNPARALLEL * INTERNPARALLEL should not exceed provided job slots" {
|
||||
PARALLELMFLAGS='-j10'
|
||||
EXPECTED='10'
|
||||
EXTERNPARALLEL="$("${MAKE[@]}" "$PARALLELMFLAGS" testhelper-print-EXTERNPARALLEL)"
|
||||
INTERNPARALLEL="$("${MAKE[@]}" "$PARALLELMFLAGS" testhelper-print-INTERNPARALLEL)"
|
||||
VALUE="$(($EXTERNPARALLEL * $INTERNPARALLEL))"
|
||||
echo "$VALUE != $EXPECTED"
|
||||
[ "$VALUE" -eq "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "standardrules_mk EXTERNPARALLEL should not exceed active targets" {
|
||||
EXPECTED="$("${MAKE[@]}" testhelper-print-JOBS)"
|
||||
VALUE="$("${MAKE[@]}" testhelper-print-EXTERNPARALLEL)"
|
||||
echo "$VALUE <= $EXPECTED"
|
||||
[ "$VALUE" -le "$EXPECTED" ]
|
||||
}
|
||||
|
||||
@test "standardrules_mk MAKEFLAGS should contain output-sync option when job slots greater than 1" {
|
||||
if ! make_has_required_version '4'; then
|
||||
skip "make version too old '$("${MAKE[@]}" --version)'"
|
||||
fi
|
||||
|
||||
run "${MAKE[@]}" testhelper-print-MAKEFLAGS EXTERNPARALLEL="32"
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "-Otarget" ]]
|
||||
}
|
||||
|
||||
@test "standardrules_mk MAKEFLAGS should not contain output-sync option when job slots equal to 1" {
|
||||
run "${MAKE[@]}" testhelper-print-MAKEFLAGS EXTERNPARALLEL="1"
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "-Otarget" ]]
|
||||
}
|
||||
164
build/dobuild/tests/70_cmake_docker_mk.bats
Normal file
164
build/dobuild/tests/70_cmake_docker_mk.bats
Normal file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
PROJECTPATH="$(readlink -f "$BATS_TEST_DIRNAME/..")"
|
||||
FIXTUREPATH="$(readlink -f "$BATS_TEST_DIRNAME/fixtures/cmake-gtest-example")"
|
||||
BUILDDIR="$(mktemp --directory --tmpdir="$BATS_TMPDIR" cmake_XXXXXXXXXX)"
|
||||
MAKE=(timeout --preserve-status --signal=SIGTERM 300 "make" --no-print-directory -C "$FIXTUREPATH" -f Makefile -f "$BATS_TEST_DIRNAME/test_helper.mk")
|
||||
|
||||
export DOBUILD_BUILDDIR="$BUILDDIR"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf "$BUILDDIR"
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk has required deps" {
|
||||
"${MAKE[@]}" --version
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk has required makefile deps" {
|
||||
"${MAKE[@]}" testhelper-print-MAKEFILE_DEPS | sort -u | parallel --keep-order command -V
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk should run default target 'all' with make generator by default" {
|
||||
run "${MAKE[@]}"
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
run "${MAKE[@]}"
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ ! "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ ! "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk build should be reproducible using make generator" {
|
||||
run "${MAKE[@]}"
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
mv "$BUILDDIR/.build/"*/alltests "$BUILDDIR"
|
||||
rm -rf "$BUILDDIR/.build"
|
||||
|
||||
run "${MAKE[@]}"
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
diff <(xxd "$BUILDDIR/.build/"*/alltests) <(xxd "$BUILDDIR/alltests")
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk should run default target 'all' with ninja generator" {
|
||||
run "${MAKE[@]}" CMAKE_GENERATOR=ninja
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
run "${MAKE[@]}" CMAKE_GENERATOR=ninja
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ ! "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "ninja: no work to do" ]]
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk build should be reproducible using ninja generator" {
|
||||
run "${MAKE[@]}" CMAKE_GENERATOR=ninja
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
mv "$BUILDDIR/.build/"*/alltests "$BUILDDIR"
|
||||
rm -rf "$BUILDDIR/.build"
|
||||
|
||||
run "${MAKE[@]}" CMAKE_GENERATOR=ninja
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
diff <(xxd "$BUILDDIR/.build/"*/alltests) <(xxd "$BUILDDIR/alltests")
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk should run tests when check target is triggered after a successful built" {
|
||||
run "${MAKE[@]}"
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
run "${MAKE[@]}" check
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ ! "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "100% tests passed, 0 tests failed out of 1" ]]
|
||||
|
||||
run "${MAKE[@]}" check
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ ! "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "100% tests passed, 0 tests failed out of 1" ]]
|
||||
}
|
||||
|
||||
@test "cmake_docker_mk should run tests with memcheck when memcheck target is triggered after a successful built" {
|
||||
run debug_trace "${MAKE[@]}"
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[@]}" =~ "Linking CXX executable alltests" ]]
|
||||
|
||||
"${MAKE[@]}" debug-print-MEMCHECKFILTER
|
||||
run debug_trace "${MAKE[@]}" memcheck
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ ! "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "Memory check" ]]
|
||||
[[ "${lines[@]}" =~ "100% tests passed, 0 tests failed out of 1" ]]
|
||||
|
||||
"${MAKE[@]}" debug-print-MEMCHECKFILTER
|
||||
run debug_trace "${MAKE[@]}" memcheck
|
||||
|
||||
printf -- '%s\n' "${lines[@]}"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "${lines[@]}" =~ "Configuring done" ]]
|
||||
[[ ! "${lines[@]}" =~ "Generating done" ]]
|
||||
[[ "${lines[@]}" =~ "Memory check" ]]
|
||||
[[ "${lines[@]}" =~ "100% tests passed, 0 tests failed out of 1" ]]
|
||||
}
|
||||
|
||||
19
build/dobuild/tests/fixtures/cmake-gtest-example/CMakeLists.txt
vendored
Normal file
19
build/dobuild/tests/fixtures/cmake-gtest-example/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(cmake-gtest-example)
|
||||
|
||||
option(POSITION_INDEPENDENT_CODE "This variable is used to initialize the POSITION_INDEPENDENT_CODE property on all the targets" ON)
|
||||
|
||||
include(CTest)
|
||||
|
||||
add_executable(alltests
|
||||
test_stringcompare.cpp
|
||||
)
|
||||
|
||||
target_include_directories(alltests PUBLIC ${GTEST_INCLUDE_DIRS})
|
||||
target_compile_options(alltests PUBLIC -Wall -Wextra ${GTEST_CFLAGS})
|
||||
target_link_libraries(alltests PUBLIC -pthread ${GTEST_LIBRARIES} gtest_main gtest)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME alltests COMMAND alltests)
|
||||
|
||||
95
build/dobuild/tests/fixtures/cmake-gtest-example/Makefile
vendored
Normal file
95
build/dobuild/tests/fixtures/cmake-gtest-example/Makefile
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
SHELL := /bin/sh
|
||||
MAKEFILE := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
MAKEFLAGS += --no-builtin-rules
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
.PHONY: default
|
||||
default: all
|
||||
|
||||
#######################################################################################################################
|
||||
# Overridable project defaults
|
||||
|
||||
DOBUILD_TOPDIR ?= $(DOBUILDDIR)
|
||||
DOBUILD_PROJECTDIR ?= $(patsubst %/,%,$(dir $(MAKEFILE)))
|
||||
|
||||
PROJECTDIR = $(DOBUILD_PROJECTDIR)
|
||||
DOBUILDDIR ?= $(PROJECTDIR)/../../..
|
||||
|
||||
include $(DOBUILDDIR)/defaults.mk
|
||||
|
||||
#######################################################################################################################
|
||||
# Project defaults and macros
|
||||
|
||||
DEFAULTTARGET = x86_64-ubuntu@bionic+builder
|
||||
|
||||
FETCHDIR = $(BUILDDIR)/.deps
|
||||
|
||||
#######################################################################################################################
|
||||
# Project dependencies
|
||||
|
||||
DUMB_INIT_VERSION = 1.2.2
|
||||
IMAGE_BUILDARGS += DUMB_INIT_VERSION=$(DUMB_INIT_VERSION)
|
||||
IMAGE_BUILDARGS += DUMB_INIT_MTIME=$(call mtime,$(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz)
|
||||
FETCH_TARGETS += $(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz
|
||||
$(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: URL = https://github.com/Yelp/dumb-init/archive/v$(DUMB_INIT_VERSION).tar.gz
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: MD5 = 6166084b05772cdcf615a762c6f3b32e
|
||||
|
||||
GTEST_VERSION = 1.8.0
|
||||
IMAGE_BUILDARGS += GTEST_VERSION=$(GTEST_VERSION)
|
||||
IMAGE_BUILDARGS += GTEST_MTIME=$(call mtime,$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz)
|
||||
FETCH_TARGETS += $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz
|
||||
$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := 16877098823401d1bf2ed7891d7dce36
|
||||
|
||||
#######################################################################################################################
|
||||
# Architecture-specific rule target configuration
|
||||
|
||||
CMAKE_TARGETS += x86_64-ubuntu@bionic+builder
|
||||
DOCKER_TARGETS += $(CMAKE_TARGETS)
|
||||
|
||||
#######################################################################################################################
|
||||
# Common rule target configuration
|
||||
|
||||
CURLFLAGS += -s
|
||||
|
||||
DOCKER_RUNFLAGS += --cap-add SYS_PTRACE
|
||||
DOCKER_RUNFLAGS += --security-opt seccomp=unconfined
|
||||
|
||||
OUTDIRS += $(OUTDIR)/src
|
||||
|
||||
EXTRACT_TARGETS += $(patsubst $(FETCHDIR)/%.tar.gz,$(OUTDIR)/src/%,$(FETCH_TARGETS))
|
||||
|
||||
#######################################################################################################################
|
||||
# Makefile dependencies
|
||||
|
||||
MAKEFILE_DEPS += gzip
|
||||
MAKEFILE_DEPS += tar
|
||||
MAKEFILE_DEPS += touch
|
||||
MAKEFILE_DEPS += cp
|
||||
MAKEFILE_DEPS += mkdir
|
||||
|
||||
#######################################################################################################################
|
||||
# Rules
|
||||
|
||||
include $(DOBUILDDIR)/cmake.mk
|
||||
include $(DOBUILDDIR)/docker.mk
|
||||
include $(DOBUILDDIR)/standardrules.mk
|
||||
|
||||
$(OUTDIR)/src/%: $(FETCHDIR)/%.tar.gz | $(OUTDIRS)
|
||||
$(SILENT) \
|
||||
$(call echo_if_silent_cmd,tar -C $(dir $@) -xf $<) \
|
||||
&& tar -I 'gzip -n' -C $(dir $@) -xf $< \
|
||||
&& touch $@
|
||||
|
||||
$(OUTDIR)/docker/%.dockerfile : $(PROJECTDIR)/%.dockerfile | $(OUTDIRS)
|
||||
cp $< $@
|
||||
|
||||
$(FETCH_TARGETS): | $(FETCHDIR)
|
||||
$(SILENT)$(call curl,$@,$(URL),$(MD5))
|
||||
|
||||
$(FETCHDIR):
|
||||
$(SILENT)mkdir -p $@
|
||||
|
||||
.DELETE_ON_ERROR: $(FETCH_TARGETS)
|
||||
|
||||
24
build/dobuild/tests/fixtures/cmake-gtest-example/test_stringcompare.cpp
vendored
Normal file
24
build/dobuild/tests/fixtures/cmake-gtest-example/test_stringcompare.cpp
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
char const actualValTrue[] = "hello gtest";
|
||||
char const actualValFalse[] = "hello world";
|
||||
char const expectVal[] = "hello gtest";
|
||||
|
||||
TEST(StrCompare, Equal)
|
||||
{
|
||||
EXPECT_STREQ(expectVal, actualValTrue);
|
||||
}
|
||||
|
||||
TEST(StrCompare, NotEqual)
|
||||
{
|
||||
EXPECT_STRNE(expectVal, actualValFalse);
|
||||
}
|
||||
|
||||
TEST(StrCompare, WithNonReproducibleValues)
|
||||
{
|
||||
EXPECT_STREQ(__DATE__, __DATE__);
|
||||
EXPECT_STREQ(__TIME__, __TIME__);
|
||||
}
|
||||
94
build/dobuild/tests/fixtures/cmake-gtest-example/x86_64-ubuntu-builder.dockerfile
vendored
Normal file
94
build/dobuild/tests/fixtures/cmake-gtest-example/x86_64-ubuntu-builder.dockerfile
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
ARG REGISTRY_PREFIX=''
|
||||
ARG CODENAME=bionic
|
||||
|
||||
FROM ${REGISTRY_PREFIX}ubuntu:${CODENAME} as builder
|
||||
|
||||
ARG TZ=UTC
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=${LANG}
|
||||
|
||||
RUN set -x \
|
||||
&& installdeps="tzdata" \
|
||||
&& rm -f /etc/apt/sources.list.d/*.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends $installdeps \
|
||||
&& ls /usr/share/zoneinfo \
|
||||
&& cp -H --remove-destination "/usr/share/zoneinfo/$TZ" /tmp/localtime \
|
||||
&& { apt-get purge -y $installdeps || true; } \
|
||||
&& mv /tmp/localtime /etc/localtime \
|
||||
&& echo "$TZ" > /etc/timezone \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends \
|
||||
build-essential \
|
||||
cmake \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY src /usr/local/src
|
||||
|
||||
ARG PARALLELMFLAGS=-j2
|
||||
|
||||
ARG DUMB_INIT_VERSION=1.2.2
|
||||
ARG DUMB_INIT_MTIME=
|
||||
RUN set -x \
|
||||
&& builddeps="vim-common" \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends $builddeps \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& [ -n "$DUMB_INIT_MTIME" ] && export SOURCE_DATE_EPOCH="$DUMB_INIT_MTIME" \
|
||||
&& builddir="/tmp/out" \
|
||||
&& mkdir -p "$builddir" \
|
||||
&& cd "$builddir" \
|
||||
&& cp -R "/usr/local/src/dumb-init-$DUMB_INIT_VERSION" . \
|
||||
&& cd "dumb-init-$DUMB_INIT_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" \
|
||||
&& chmod +x dumb-init \
|
||||
&& mv dumb-init /usr/local/bin/dumb-init \
|
||||
&& dumb-init --version \
|
||||
&& rm -rf "$builddir" \
|
||||
&& apt-get purge -y $builddeps
|
||||
|
||||
ARG GTEST_VERSION=1.8.1
|
||||
ARG GTEST_MTIME=
|
||||
|
||||
RUN set -x \
|
||||
&& [ -n "$GTEST_MTIME" ] && export SOURCE_DATE_EPOCH="$GTEST_MTIME" \
|
||||
&& builddir="/tmp/out" \
|
||||
&& mkdir -p "$builddir" \
|
||||
&& cd "$builddir" \
|
||||
&& cmake "/usr/local/src/googletest-release-$GTEST_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf "$builddir"
|
||||
|
||||
FROM ${REGISTRY_PREFIX}ubuntu:${CODENAME}
|
||||
|
||||
ARG TZ=UTC
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=${LANG}
|
||||
|
||||
COPY --from=builder /usr/local /usr/local
|
||||
COPY --from=builder /etc/localtime /etc/localtime
|
||||
COPY --from=builder /etc/timezone /etc/timezone
|
||||
COPY --from=builder /etc/apt/sources.list.d /etc/apt/sources.list.d
|
||||
|
||||
RUN set -x \
|
||||
&& rm -f /etc/apt/sources.list.d/*.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends \
|
||||
build-essential \
|
||||
cmake \
|
||||
ninja-build \
|
||||
pkg-config \
|
||||
gdb \
|
||||
gdbserver \
|
||||
valgrind \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
|
||||
ARG USERID=1000
|
||||
RUN set -x \
|
||||
&& useradd -u "$USERID" -ms /bin/bash user
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
CMD [ "/bin/bash" ]
|
||||
|
||||
18
build/dobuild/tests/fixtures/make-gtest-example/Makefile
vendored
Normal file
18
build/dobuild/tests/fixtures/make-gtest-example/Makefile
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# Makefile for gtest example
|
||||
|
||||
CPPFLAGS = -I /usr/local/include
|
||||
CXXFLAGS = -c -Wall
|
||||
LDFLAGS = -L /usr/local/lib -l gtest_main -l gtest -l pthread
|
||||
|
||||
TARGET = alltests
|
||||
OBJECTS = test_stringcompare.o
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CXX) -o $@ $^ $(LD_FLAGS)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
||||
|
||||
.PHONY: all clean
|
||||
18
build/dobuild/tests/fixtures/make-gtest-example/test_stringcompare.cpp
vendored
Normal file
18
build/dobuild/tests/fixtures/make-gtest-example/test_stringcompare.cpp
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <gtest/gtest.h> // googletest header file
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
char const actualValTrue[] = "hello gtest";
|
||||
char const actualValFalse[] = "hello world";
|
||||
char const expectVal[] = "hello gtest";
|
||||
|
||||
TEST(StrCompare, CStrEqual)
|
||||
{
|
||||
EXPECT_STREQ(expectVal, actualValTrue);
|
||||
}
|
||||
|
||||
TEST(StrCompare, CStrNotEqual)
|
||||
{
|
||||
EXPECT_STRNE(expectVal, actualValFalse);
|
||||
}
|
||||
27
build/dobuild/tests/get_container_id.dockerfile
Normal file
27
build/dobuild/tests/get_container_id.dockerfile
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
ARG REGISTRY_PREFIX=''
|
||||
ARG DOCKER_VERSION=18.09.6
|
||||
|
||||
FROM ${REGISTRY_PREFIX}docker:${DOCKER_VERSION}-dind
|
||||
|
||||
ARG USERID=1000
|
||||
ARG PROJECTPATH=/home/user/dobuild
|
||||
|
||||
RUN set -x \
|
||||
&& adduser -u "$USERID" -s /bin/sh -D user \
|
||||
&& mkdir -p "$PROJECTPATH" \
|
||||
&& chown user:user "$PROJECTPATH"
|
||||
|
||||
COPY --chown=user:user . "$PROJECTPATH"
|
||||
WORKDIR "$PROJECTPATH/bin"
|
||||
|
||||
VOLUME "$PROJECTPATH"
|
||||
167
build/dobuild/tests/runners/bats.dockerfile
Normal file
167
build/dobuild/tests/runners/bats.dockerfile
Normal file
@@ -0,0 +1,167 @@
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
ARG REGISTRY_PREFIX=''
|
||||
ARG CODENAME=trusty
|
||||
|
||||
FROM ${REGISTRY_PREFIX}ubuntu:${CODENAME} as builder
|
||||
|
||||
ARG TZ=UTC
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=${LANG}
|
||||
|
||||
ARG PARALLELMFLAGS=
|
||||
|
||||
ARG DOCKER_CHANNEL=stable
|
||||
ARG DOCKER_VERSION=18.09.6
|
||||
ARG DOCKER_MD5=a6be1e734421d05abfc4d3e28997e271
|
||||
ARG DOCKER_DOWNLOAD=https://download.docker.com
|
||||
|
||||
ARG DOCKER_HOME="/usr/local/lib/docker-$DOCKER_VERSION"
|
||||
|
||||
ARG CAPATH="./ca-certificates"
|
||||
COPY $CAPATH /usr/local/share/ca-certificates
|
||||
|
||||
RUN set -x \
|
||||
&& { update-ca-certificates || true; } \
|
||||
&& installdeps="tzdata" \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends $installdeps \
|
||||
&& ls /usr/share/zoneinfo \
|
||||
&& cp -H --remove-destination "/usr/share/zoneinfo/$TZ" /tmp/localtime \
|
||||
&& { apt-get purge -y $installdeps || true; } \
|
||||
&& mv /tmp/localtime /etc/localtime \
|
||||
&& echo "$TZ" > /etc/timezone \
|
||||
&& apt-get install --yes --no-install-recommends \
|
||||
ca-certificates \
|
||||
curl \
|
||||
openssl \
|
||||
build-essential \
|
||||
make \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& update-ca-certificates
|
||||
|
||||
RUN set -x \
|
||||
&& curl -fSL -s "$DOCKER_DOWNLOAD/linux/static/${DOCKER_CHANNEL}/$(uname -m)/docker-${DOCKER_VERSION}.tgz" -o docker.tgz \
|
||||
&& md5sum docker.tgz \
|
||||
&& echo "$DOCKER_MD5 docker.tgz" | md5sum -c - \
|
||||
&& tar -xzvf docker.tgz \
|
||||
&& mkdir -p "$DOCKER_HOME" \
|
||||
&& mv docker/docker "$DOCKER_HOME" \
|
||||
&& rm -rf docker \
|
||||
&& rm docker.tgz \
|
||||
&& ln -s "$DOCKER_HOME/docker" /usr/local/bin/docker
|
||||
|
||||
ARG BATS_VERSION=1.1.0
|
||||
ARG BATS_MD5=0cb16021aa8f75a29240434c5aaae0a1
|
||||
ARG BATS_DOWNLOAD=https://github.com/bats-core
|
||||
|
||||
RUN set -x \
|
||||
&& builddeps="coreutils ncurses-bin bash" \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends $builddeps \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& curl -fSL -s "$BATS_DOWNLOAD/bats-core/archive/v$BATS_VERSION.tar.gz" -o bats.tar.gz \
|
||||
&& md5sum bats.tar.gz \
|
||||
&& echo "$BATS_MD5 bats.tar.gz" | md5sum -c - \
|
||||
&& tar -xzvf bats.tar.gz \
|
||||
&& bash "bats-core-$BATS_VERSION/install.sh" /usr/local \
|
||||
&& rm -rf "bats-core-$BATS_VERSION" \
|
||||
&& rm bats.tar.gz
|
||||
|
||||
ARG DUMB_INIT_VERSION=1.2.2
|
||||
ARG DUMB_INIT_MD5=6166084b05772cdcf615a762c6f3b32e
|
||||
ARG DUMB_INIT_DOWNLOAD=https://github.com/Yelp/dumb-init
|
||||
|
||||
RUN set -x \
|
||||
&& parallelMFlags="$PARALLELMFLAGS" \
|
||||
&& [ -n "$parallelMFlags" ] || parallelMFlags="-j$(nproc)" \
|
||||
&& builddeps="vim-common" \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends $builddeps \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& curl -fSL -s "$DUMB_INIT_DOWNLOAD/archive/v${DUMB_INIT_VERSION}.tar.gz" -o dumb-init.tar.gz \
|
||||
&& md5sum dumb-init.tar.gz \
|
||||
&& echo "$DUMB_INIT_MD5 dumb-init.tar.gz" | md5sum -c - \
|
||||
&& export SOURCE_DATE_EPOCH="$(stat -c '%Y' dumb-init.tar.gz)" \
|
||||
&& tar -xzvf dumb-init.tar.gz \
|
||||
&& cd "dumb-init-$DUMB_INIT_VERSION" \
|
||||
&& make "$parallelMFlags" \
|
||||
&& chmod +x dumb-init \
|
||||
&& cp dumb-init /usr/local/bin/dumb-init \
|
||||
&& cd .. \
|
||||
&& rm -rf "dumb-init-$DUMB_INIT_VERSION" \
|
||||
&& rm dumb-init.tar.gz \
|
||||
&& apt-get purge -y $builddeps
|
||||
|
||||
ARG LIBFAKETIME_VERSION=0.9.7
|
||||
ARG LIBFAKETIME_MD5=8617e2c6caf0977b3ce9a271f867302c
|
||||
ARG LIBFAKETIME_DOWNLOAD=https://github.com/wolfcw/libfaketime
|
||||
|
||||
RUN set -x \
|
||||
&& parallelMFlags="$PARALLELMFLAGS" \
|
||||
&& [ -n "$parallelMFlags" ] || parallelMFlags="-j$(nproc)" \
|
||||
&& curl -fSL -s "$LIBFAKETIME_DOWNLOAD/archive/v${LIBFAKETIME_VERSION}.tar.gz" -o libfaketime.tar.gz \
|
||||
&& md5sum libfaketime.tar.gz \
|
||||
&& echo "$LIBFAKETIME_MD5 libfaketime.tar.gz" | md5sum -c - \
|
||||
&& export SOURCE_DATE_EPOCH="$(stat -c '%Y' libfaketime.tar.gz)" \
|
||||
&& tar -xzvf libfaketime.tar.gz \
|
||||
&& cd "libfaketime-$LIBFAKETIME_VERSION" \
|
||||
&& prefix='/usr/local' \
|
||||
&& make "$parallelMFlags" \
|
||||
CFLAGS="-fpic -lpthread -Wno-error -D'PREFIX=\"${prefix}\"' -D'LIBDIRNAME=\"lib\"'" \
|
||||
LDFLAGS='-fpic -lpthread' \
|
||||
&& make install \
|
||||
&& cd .. \
|
||||
&& rm -rf "libfaketime-$LIBFAKETIME_VERSION" \
|
||||
&& rm libfaketime.tar.gz
|
||||
|
||||
FROM ${REGISTRY_PREFIX}ubuntu:${CODENAME}
|
||||
|
||||
ARG TZ=UTC
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=${LANG}
|
||||
|
||||
COPY --from=builder /usr/local /usr/local
|
||||
COPY --from=builder /etc/localtime /etc/localtime
|
||||
COPY --from=builder /etc/timezone /etc/timezone
|
||||
COPY --from=builder /etc/apt/sources.list.d /etc/apt/sources.list.d
|
||||
|
||||
RUN set -x \
|
||||
&& { update-ca-certificates || true; } \
|
||||
&& apt-get update \
|
||||
&& apt-get install --yes --no-install-recommends \
|
||||
coreutils \
|
||||
ncurses-bin \
|
||||
bash \
|
||||
procps \
|
||||
parallel \
|
||||
ca-certificates \
|
||||
make \
|
||||
git \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& update-ca-certificates \
|
||||
&& useradd -ms /bin/bash user
|
||||
|
||||
USER user
|
||||
|
||||
# Accept the citation notice of GNU parallel (we aren't using this in a
|
||||
# context where it make sense to cite GNU Parallel).
|
||||
RUN set -x \
|
||||
&& mkdir -p ~/.parallel \
|
||||
&& touch ~/.parallel/will-cite
|
||||
|
||||
RUN dumb-init --version
|
||||
RUN parallel --version
|
||||
RUN docker --version
|
||||
RUN bats --version
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
17
build/dobuild/tests/runners/dind-bind_mount.yml
Normal file
17
build/dobuild/tests/runners/dind-bind_mount.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
version: "2.4"
|
||||
|
||||
services:
|
||||
dind:
|
||||
volumes:
|
||||
- .:${COMPOSEENV_PROJECTPATH}:ro
|
||||
|
||||
17
build/dobuild/tests/runners/dind-volumes_from.yml
Normal file
17
build/dobuild/tests/runners/dind-volumes_from.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
version: "2.4"
|
||||
|
||||
services:
|
||||
dind:
|
||||
volumes_from:
|
||||
- container:${COMPOSEENV_VOLUMESFROM}:ro
|
||||
|
||||
24
build/dobuild/tests/runners/dind.dockerfile
Normal file
24
build/dobuild/tests/runners/dind.dockerfile
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
ARG REGISTRY_PREFIX=''
|
||||
ARG DOCKER_VERSION=18.09.6
|
||||
|
||||
FROM ${REGISTRY_PREFIX}docker:${DOCKER_VERSION}-dind
|
||||
|
||||
ARG CAPATH="./ca-certificates"
|
||||
COPY $CAPATH /usr/local/share/ca-certificates
|
||||
|
||||
RUN set -x \
|
||||
&& { update-ca-certificates || true; } \
|
||||
&& apk add --no-cache \
|
||||
ca-certificates \
|
||||
&& update-ca-certificates
|
||||
|
||||
29
build/dobuild/tests/test_helper.bash
Normal file
29
build/dobuild/tests/test_helper.bash
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
DOCKER="${DOCKER:-docker}"
|
||||
export DOCKER
|
||||
|
||||
USERID="${USERID:-$(id -u)}"
|
||||
|
||||
_cancel() {
|
||||
if [[ -t 3 ]]; then
|
||||
exec 3<&-
|
||||
fi
|
||||
}
|
||||
|
||||
debug_trace() {
|
||||
echo "${@}" 1>&2
|
||||
"${@}"
|
||||
}
|
||||
|
||||
# workaround to avoid deadlocks on signal termination
|
||||
trap _cancel SIGINT SIGTERM
|
||||
24
build/dobuild/tests/test_helper.mk
Normal file
24
build/dobuild/tests/test_helper.mk
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# This file is part of dobuild.
|
||||
# Copyright (c) 2019 Contributors as noted in the AUTHORS file.
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
.PHONY: testhelper-default
|
||||
testhelper-default:
|
||||
|
||||
.PHONY: testhelper-print-%
|
||||
testhelper-print-%:
|
||||
@printf '%s\n' $($*)
|
||||
|
||||
.PHONY: testhelper-default-silent
|
||||
testhelper-default-silent:
|
||||
$(SILENT)true
|
||||
|
||||
.PHONY: testhelper-recursive-print-%
|
||||
testhelper-recursive-print-%:
|
||||
@$(MAKE) $(MFLAGS) $(addprefix -f,$(MAKEFILE_LIST)) testhelper-print-$* $(MAKEOVERRIDES)
|
||||
Reference in New Issue
Block a user