Skip to content

Commit c12954e

Browse files
committed
Added snapshot tests
1 parent d63ff0f commit c12954e

File tree

59 files changed

+857
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+857
-10
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tmc-langs-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ url = "2.2.2"
3232
walkdir = "2.3.2"
3333

3434
[dev-dependencies]
35-
insta = { version = "1.26.0", features = ["yaml", "glob", "filters"] }
35+
insta = { version = "1.28.0", features = ["yaml", "glob", "filters"] }
3636
simple_logger = "4.0.0"
3737
tempfile = "3.3.0"
3838

crates/tmc-langs-cli/tests/integration.rs

Lines changed: 185 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clap::Parser;
22
use std::path::Path;
33
use tempfile::{tempdir, NamedTempFile, TempDir};
4+
use tmc_langs::Compression;
45
use tmc_langs_cli::app::Cli;
56
use walkdir::WalkDir;
67

@@ -22,6 +23,38 @@ fn cp_exercise(path: &Path) -> TempDir {
2223
temp
2324
}
2425

26+
fn compress_naive(path: &impl AsRef<Path>, target: &impl AsRef<Path>, compression: Compression) {
27+
let cli = Cli::parse_from([
28+
"tmc-langs-cli",
29+
"--pretty",
30+
"compress-project",
31+
"--exercise-path",
32+
path_str(path),
33+
"--output-path",
34+
path_str(target),
35+
"--compression",
36+
&compression.to_string(),
37+
"--naive",
38+
]);
39+
tmc_langs_cli::run(cli).unwrap();
40+
}
41+
42+
fn extract_naive(path: &impl AsRef<Path>, target: &impl AsRef<Path>, compression: Compression) {
43+
let cli = Cli::parse_from([
44+
"tmc-langs-cli",
45+
"--pretty",
46+
"extract-project",
47+
"--archive-path",
48+
path_str(path),
49+
"--output-path",
50+
path_str(target),
51+
"--compression",
52+
&compression.to_string(),
53+
"--naive",
54+
]);
55+
tmc_langs_cli::run(cli).unwrap();
56+
}
57+
2558
fn path_str(path: &impl AsRef<Path>) -> &str {
2659
path.as_ref().to_str().unwrap()
2760
}
@@ -40,6 +73,7 @@ fn sorted_list_of_files(path: &impl AsRef<Path>) -> Vec<String> {
4073

4174
// wrapper for all sample exercise tests
4275
fn test(f: impl Fn(&Path)) {
76+
let _ = env_logger::try_init();
4377
insta::with_settings!({
4478
filters => vec![
4579
// replace Windows-style path separators
@@ -56,7 +90,8 @@ fn test(f: impl Fn(&Path)) {
5690
(r"C:/\S*/Temp/\S*", "[PATH]"),
5791
],
5892
}, {
59-
insta::glob!("sample_exercises/*/*", |exercise| {
93+
insta::glob!("../../../", "sample_exercises/*/*", |exercise| {
94+
println!("testing {exercise:?}");
6095
f(exercise)
6196
})
6297
})
@@ -100,3 +135,152 @@ fn clean() {
100135
insta::assert_yaml_snapshot!(files);
101136
})
102137
}
138+
139+
#[test]
140+
fn compress_project_tar() {
141+
test(|exercise| {
142+
let target = NamedTempFile::new().unwrap();
143+
let cli = Cli::parse_from([
144+
"tmc-langs-cli",
145+
"--pretty",
146+
"compress-project",
147+
"--exercise-path",
148+
path_str(&exercise),
149+
"--output-path",
150+
path_str(&target),
151+
"--compression",
152+
"tar",
153+
]);
154+
let output = tmc_langs_cli::run(cli).unwrap();
155+
insta::assert_yaml_snapshot!(output);
156+
157+
let extracted = tempdir().unwrap();
158+
extract_naive(&target, &extracted, Compression::Tar);
159+
let files = sorted_list_of_files(&extracted);
160+
insta::assert_yaml_snapshot!(files);
161+
})
162+
}
163+
164+
#[test]
165+
fn compress_project_zip() {
166+
test(|exercise| {
167+
let target = NamedTempFile::new().unwrap();
168+
let cli = Cli::parse_from([
169+
"tmc-langs-cli",
170+
"--pretty",
171+
"compress-project",
172+
"--exercise-path",
173+
path_str(&exercise),
174+
"--output-path",
175+
path_str(&target),
176+
// zip should be the default
177+
// "--compression",
178+
// "zip",
179+
]);
180+
let output = tmc_langs_cli::run(cli).unwrap();
181+
insta::assert_yaml_snapshot!(output);
182+
183+
let extracted = tempdir().unwrap();
184+
extract_naive(&target, &extracted, Compression::Zip);
185+
let files = sorted_list_of_files(&extracted);
186+
insta::assert_yaml_snapshot!(files);
187+
})
188+
}
189+
190+
#[test]
191+
fn compress_project_zstd() {
192+
test(|exercise| {
193+
let target = NamedTempFile::new().unwrap();
194+
let cli = Cli::parse_from([
195+
"tmc-langs-cli",
196+
"--pretty",
197+
"compress-project",
198+
"--exercise-path",
199+
path_str(&exercise),
200+
"--output-path",
201+
path_str(&target),
202+
"--compression",
203+
"zstd",
204+
]);
205+
let output = tmc_langs_cli::run(cli).unwrap();
206+
insta::assert_yaml_snapshot!(output);
207+
208+
let extracted = tempdir().unwrap();
209+
extract_naive(&target, &extracted, Compression::TarZstd);
210+
let files = sorted_list_of_files(&extracted);
211+
insta::assert_yaml_snapshot!(files);
212+
})
213+
}
214+
215+
#[test]
216+
fn extract_project_tar() {
217+
test(|exercise| {
218+
let compressed = NamedTempFile::new().unwrap();
219+
compress_naive(&exercise, &compressed, Compression::Tar);
220+
let target = tempdir().unwrap();
221+
let cli = Cli::parse_from([
222+
"tmc-langs-cli",
223+
"--pretty",
224+
"extract-project",
225+
"--archive-path",
226+
path_str(&compressed),
227+
"--output-path",
228+
path_str(&target),
229+
"--compression",
230+
"tar",
231+
]);
232+
let output = tmc_langs_cli::run(cli).unwrap();
233+
insta::assert_yaml_snapshot!(output);
234+
let files = sorted_list_of_files(&target);
235+
insta::assert_yaml_snapshot!(files);
236+
})
237+
}
238+
239+
#[test]
240+
fn extract_project_zip() {
241+
test(|exercise| {
242+
let compressed = NamedTempFile::new().unwrap();
243+
compress_naive(&exercise, &compressed, Compression::Zip);
244+
let target = tempdir().unwrap();
245+
let cli = Cli::parse_from([
246+
"tmc-langs-cli",
247+
"--pretty",
248+
"extract-project",
249+
"--archive-path",
250+
path_str(&compressed),
251+
"--output-path",
252+
path_str(&target),
253+
// zip should be the default
254+
// "--compression",
255+
// "zip",
256+
]);
257+
let output = tmc_langs_cli::run(cli).unwrap();
258+
insta::assert_yaml_snapshot!(output);
259+
let files = sorted_list_of_files(&target);
260+
insta::assert_yaml_snapshot!(files);
261+
})
262+
}
263+
264+
#[test]
265+
fn extract_project_zstd() {
266+
test(|exercise| {
267+
let compressed = NamedTempFile::new().unwrap();
268+
compress_naive(&exercise, &compressed, Compression::TarZstd);
269+
let target = tempdir().unwrap();
270+
let cli = Cli::parse_from([
271+
"tmc-langs-cli",
272+
"--pretty",
273+
"extract-project",
274+
"--archive-path",
275+
path_str(&compressed),
276+
"--output-path",
277+
path_str(&target),
278+
"--compression",
279+
"zstd",
280+
]);
281+
let output = tmc_langs_cli::run(cli).unwrap();
282+
insta::assert_yaml_snapshot!(output);
283+
let files = sorted_list_of_files(&target);
284+
insta::assert_yaml_snapshot!(files);
285+
})
286+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/tmc-langs-cli/tests/integration.rs
3+
expression: output
4+
input_file: crates/tmc-langs-cli/tests/sample_exercises/make/failing-exercise
5+
---
6+
output-kind: output-data
7+
status: finished
8+
message: ran checkstyle
9+
result: executed-command
10+
data: ~
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/tmc-langs-cli/tests/integration.rs
3+
expression: output
4+
input_file: crates/tmc-langs-cli/tests/sample_exercises/make/passing-exercise
5+
---
6+
output-kind: output-data
7+
status: finished
8+
message: ran checkstyle
9+
result: executed-command
10+
data: ~
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/tmc-langs-cli/tests/integration.rs
3+
expression: output
4+
input_file: crates/tmc-langs-cli/tests/sample_exercises/make/valgrind-failing-exercise
5+
---
6+
output-kind: output-data
7+
status: finished
8+
message: ran checkstyle
9+
result: executed-command
10+
data: ~
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/tmc-langs-cli/tests/integration.rs
3+
expression: output
4+
input_file: sample_exercises/python3/01_emoticon
5+
---
6+
output-kind: output-data
7+
status: finished
8+
message: ran checkstyle
9+
result: executed-command
10+
data: ~
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/tmc-langs-cli/tests/integration.rs
3+
expression: output
4+
input_file: sample_exercises/python3/exercise
5+
---
6+
output-kind: output-data
7+
status: finished
8+
message: ran checkstyle
9+
result: executed-command
10+
data: ~
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/tmc-langs-cli/tests/integration.rs
3+
expression: output
4+
input_file: sample_exercises/r/exercise
5+
---
6+
output-kind: output-data
7+
status: finished
8+
message: ran checkstyle
9+
result: executed-command
10+
data: ~
11+

crates/tmc-langs-cli/tests/snapshots/integration__clean@c__passing-exercise-2.snap renamed to crates/tmc-langs-cli/tests/snapshots/integration__clean@make__failing-exercise-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
source: crates/tmc-langs-cli/tests/integration.rs
33
expression: files
4-
input_file: crates/tmc-langs-cli/tests/sample_exercises/c/passing-exercise
4+
input_file: crates/tmc-langs-cli/tests/sample_exercises/make/failing-exercise
55
---
66
- Makefile
77
- src

0 commit comments

Comments
 (0)