-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstateless-journey.sh
executable file
·237 lines (201 loc) · 8.23 KB
/
stateless-journey.sh
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
set -eu
exe=${1:?First argument must be the executable to test}
root="$(cd "${0%/*}" && pwd)"
exe="$(cd "${exe%/*}" && echo "$(pwd)/${exe##*/}")"
# shellcheck disable=1090
source "$root/utilities.sh"
source "$root/helpers.sh"
snapshot="$root/snapshots"
SUCCESSFULLY=0
WITH_FAILURE=1
function remove_paths() {
sed 's_`/.*`_<redacted>_g'
}
# This filter is required as bytecounts fluctuate due to changing meta-data/timestamps
function remove_bytecounts() {
sed -E 's/[0-9]+ B/<bytecount>/g'
}
(in-clone-of https://github.com/greshake/i3status-rust
stepn "reproduce https://github.com/the-lean-crate/cargo-diet/issues/1"
(when "cargo diet in dry-run mode"
it "runs successfully" && {
expect_run ${SUCCESSFULLY} "$exe" diet -n
}
)
)
(sandbox
(with "with no cargo project"
it "fails with an error message" && {
SNAPSHOT_FILTER=remove_paths \
WITH_SNAPSHOT="$snapshot/failure-no-cargo-manifest" \
expect_run ${WITH_FAILURE} "$exe" diet
}
)
(with "with an invalid cargo project"
echo "foobar" > Cargo.toml
it "fails with a human readable error message" && {
SNAPSHOT_FILTER=remove_paths \
WITH_SNAPSHOT="$snapshot/failure-invalid-cargo-manifest" \
expect_run ${WITH_FAILURE} "$exe" diet
}
)
(with "with a cargo project that causes package failure"
cp "$root/fixtures/artichoke-cargo.toml" Cargo.toml
it "fails with a human readable error message" && {
SNAPSHOT_FILTER=remove_paths \
WITH_SNAPSHOT="$snapshot/failure-invalid-cargo-manifest-due-to-packaging-with-human-readable-error" \
expect_run ${WITH_FAILURE} "$exe" diet
}
)
(when "asking for help"
it "succeeds" && {
expect_run ${SUCCESSFULLY} "$exe" diet --help
}
)
)
(with "a cargo user and email"
export CARGO_NAME=author
export [email protected]
(sandbox
(with "a newly initialized cargo project with one dependency that doesnt exist"
step "init cargo project" &&
expect_run ${SUCCESSFULLY} cargo init --name library --bin
echo 'should-never-exist-on-cratesio = "42.21.10"' >> Cargo.toml
it "succeeds" && {
SNAPSHOT_FILTER=remove_paths \
WITH_SNAPSHOT="$snapshot/success-invalid-dependencies-but-valid-package" \
expect_run ${SUCCESSFULLY} "$exe" diet
}
(when "running it with --save-package-for-unit-test flag"
FILE_PATH=name-of-package-for-testing.rmp
it "succeeds" && {
WITH_SNAPSHOT="$snapshot/success-save-package" \
expect_run ${SUCCESSFULLY} "$exe" diet --save-package-for-unit-test "${FILE_PATH}"
}
it "creates the file at the given path" && {
expect_exists "${FILE_PATH}"
}
)
)
)
(sandbox
(with "a newly initialized cargo project"
step "init cargo project" &&
expect_run ${SUCCESSFULLY} cargo init --name library --bin
(with "the --dry-run flag set"
it "runs successfully and states the crate is lean" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project-dry-run" \
expect_run ${SUCCESSFULLY} "$exe" diet --dry-run
}
it "does not modify the Cargo.toml file" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml" "Cargo.toml"
}
)
(with "NO --dry-run flag set"
it "runs successfully and states the crate is lean" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project" \
expect_run ${SUCCESSFULLY} "$exe" diet
}
it "does not modify the Cargo.toml file" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml" "Cargo.toml"
}
)
(when "running it again"
it "runs successfully" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project" \
expect_run ${SUCCESSFULLY} "$exe" diet
}
it "produces exactly the same output as before" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml" "Cargo.toml"
}
)
(with "a new test file which is part of the src/ directory"
touch src/lib_test.rs
(with "the -n (dry-run) flag set"
it "runs successfully and prints diff information" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project-test-added-dry-run" \
expect_run ${SUCCESSFULLY} "$exe" diet -n
}
it "does not alter Cargo.toml" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml-with-tests-excluded-dry-run" "Cargo.toml"
}
)
(with "NO --dry-run flag set"
(when "running it again"
it "runs successfully and states the changes" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project-test-added" \
expect_run ${SUCCESSFULLY} "$exe" diet
}
it "produces a new include directive which explicitly excludes the new file type" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml-with-tests-excluded" "Cargo.toml"
}
)
)
)
(with "a new README file in the project root"
touch README.md
(when "running it"
it "runs successfully" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project" \
expect_run ${SUCCESSFULLY} "$exe" diet
}
it "produces the same include as before, effectively not picking up a file it should pick up!" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml-with-tests-excluded" "Cargo.toml"
}
)
(with "the --reset-manifest flag set"
(with "the --dry-run flag set"
it "runs successfully" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project-test-added-reset-dry-run" \
expect_run ${SUCCESSFULLY} "$exe" diet --reset-manifest --dry-run
}
it "does not alter the Cargo.toml file" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml-with-tests-excluded" "Cargo.toml"
}
)
(with "NO --dry-run flag set"
it "runs successfully" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project-test-added-no-dryrun" \
expect_run ${SUCCESSFULLY} "$exe" diet -r
}
it "produces a new include that includes the new file." && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml-with-tests-excluded-and-readme" "Cargo.toml"
}
)
)
(with "NO --reset-manifest flag"
it "runs successfully" && {
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project" \
expect_run ${SUCCESSFULLY} "$exe" diet
}
it "does not alter the cargo manifest" && {
expect_snapshot "$snapshot/success-include-directive-in-new-project-cargo-toml-with-tests-excluded-and-readme" "Cargo.toml"
}
)
(with "the --package-size-limit flag"
(when "the limit is lower than the actual package size"
it "runs successfully" && {
SNAPSHOT_FILTER=remove_bytecounts \
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project-limit-exceeded" \
expect_run ${WITH_FAILURE} "$exe" diet --package-size-limit 50B
}
it "does not put a file in target/package" && {
expect_run ${WITH_FAILURE} find target/package
}
)
(when "the limit is higher than the actual package size"
it "runs successfully" && {
SNAPSHOT_FILTER=remove_bytecounts \
WITH_SNAPSHOT="$snapshot/success-include-directive-in-new-project-limit-not-exceeded" \
expect_run ${SUCCESSFULLY} "$exe" diet --package-size-limit 50KB
}
it "does not put a file in target/package" && {
expect_run ${WITH_FAILURE} find target/package
}
)
)
)
)
)
)