-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRunScriptDependencyPathTest.sh
More file actions
executable file
·116 lines (99 loc) · 3.08 KB
/
Copy pathRunScriptDependencyPathTest.sh
File metadata and controls
executable file
·116 lines (99 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
set -euo pipefail
VIX_BIN="${1:?missing vix binary}"
ROOT="$(mktemp -d)"
cleanup() { rm -rf "$ROOT"; }
trap cleanup EXIT
export HOME="$ROOT/home"
mkdir -p "$HOME"
git_init_fixture() {
local dir="$1"
git -C "$dir" init -q
git -C "$dir" config user.email test@example.invalid
git -C "$dir" config user.name "Vix Test"
git -C "$dir" add .
git -C "$dir" commit -q -m init
git -C "$dir" rev-parse HEAD
}
make_fake_cmake() {
local dir="$1"
mkdir -p "$dir"
cat > "$dir/cmake" <<'SH'
#!/usr/bin/env bash
echo "cmake must not be invoked for this test" >&2
exit 87
SH
chmod +x "$dir/cmake"
}
CMAKE_REPO="$ROOT/sample-cmake"
mkdir -p "$CMAKE_REPO/include/sample" "$CMAKE_REPO/src"
cat > "$CMAKE_REPO/include/sample/sample.hpp" <<'HPP'
#pragma once
namespace sample { int answer(); }
HPP
cat > "$CMAKE_REPO/src/sample.cpp" <<'CPP'
#include <sample/sample.hpp>
namespace sample { int answer() { return 42; } }
CPP
cat > "$CMAKE_REPO/CMakeLists.txt" <<'CMAKE'
cmake_minimum_required(VERSION 3.20)
project(sample_cmake LANGUAGES CXX)
add_library(sample_lib src/sample.cpp)
add_library(sample::sample ALIAS sample_lib)
target_include_directories(sample_lib PUBLIC include)
CMAKE
CMAKE_COMMIT="$(git_init_fixture "$CMAKE_REPO")"
HEADER_REPO="$ROOT/sample-headers"
mkdir -p "$HEADER_REPO/include/headers"
cat > "$HEADER_REPO/include/headers/headers.hpp" <<'HPP'
#pragma once
namespace headers { inline int answer() { return 7; } }
HPP
HEADER_COMMIT="$(git_init_fixture "$HEADER_REPO")"
PROJECT="$ROOT/project"
mkdir -p "$PROJECT/tests"
cat > "$PROJECT/vix.app" <<APP
name = "run_perf"
type = "executable"
standard = "c++20"
sources = ["tests/test.cpp"]
[dependencies.sample]
git = "$CMAKE_REPO"
rev = "$CMAKE_COMMIT"
target = "sample::sample"
[dependencies.headers]
git = "$HEADER_REPO"
rev = "$HEADER_COMMIT"
header_only = true
include = "include"
APP
cat > "$PROJECT/tests/test.cpp" <<'CPP'
#include <iostream>
int main() { std::cout << "Hello\\n"; }
CPP
cat > "$PROJECT/tests/use_sample.cpp" <<'CPP'
#include <sample/sample.hpp>
int main() { return sample::answer() == 42 ? 0 : 1; }
CPP
cat > "$PROJECT/tests/use_headers.cpp" <<'CPP'
#include <headers/headers.hpp>
int main() { return headers::answer() == 7 ? 0 : 1; }
CPP
(cd "$PROJECT" && "$VIX_BIN" install >/dev/null)
test -e "$PROJECT/.vix/vix_deps.cmake"
FAKE_BIN="$ROOT/fake-bin"
make_fake_cmake "$FAKE_BIN"
(cd "$PROJECT/tests" && PATH="$FAKE_BIN:$PATH" "$VIX_BIN" run test.cpp --no-san >/dev/null)
(cd "$PROJECT/tests" && "$VIX_BIN" run use_sample.cpp --no-san >/dev/null)
(cd "$PROJECT/tests" && PATH="$FAKE_BIN:$PATH" "$VIX_BIN" run use_headers.cpp --no-san >/dev/null)
(cd "$PROJECT/tests" && PATH="$FAKE_BIN:$PATH" "$VIX_BIN" run test.cpp --no-san >/dev/null)
TEMP_RUN="$ROOT/temp-run"
mkdir -p "$TEMP_RUN"
cat > "$TEMP_RUN/main.cpp" <<'CPP'
#include <sample/sample.hpp>
int main() { return sample::answer() == 42 ? 0 : 1; }
CPP
(cd "$TEMP_RUN" && "$VIX_BIN" run main.cpp --no-san --dep "git=$CMAKE_REPO;rev=$CMAKE_COMMIT;target=sample::sample" >/dev/null)
test ! -e "$TEMP_RUN/vix.app"
test ! -e "$TEMP_RUN/vix.lock"
test ! -e "$TEMP_RUN/.vix"