Skip to content

Commit 54d3110

Browse files
committed
fix tests and add one
Signed-off-by: Jess Frazelle <[email protected]>
1 parent 89bdc3b commit 54d3110

File tree

18 files changed

+238
-231
lines changed

18 files changed

+238
-231
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "zoo"
3-
version = "0.2.108"
3+
version = "0.2.109"
44
edition = "2021"
55
build = "build.rs"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ impl Context<'_> {
454454
if path.is_dir() {
455455
path = path.join("main.kcl");
456456
if !path.exists() {
457-
return Err(anyhow::anyhow!("Directory does not contain a main.kcl file"));
457+
return Err(anyhow::anyhow!(
458+
"Directory `{}` does not contain a main.kcl file",
459+
path.display()
460+
));
458461
}
459462
} else {
460463
// Otherwise be sure we have a kcl file.

src/tests.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct TestItem {
99
want_out: String,
1010
want_err: String,
1111
want_code: i32,
12+
current_directory: Option<std::path::PathBuf>,
1213
}
1314

1415
struct MainContext {
@@ -158,6 +159,7 @@ async fn test_main(ctx: &mut MainContext) {
158159
want_out: "✔ Logged in as ".to_string(),
159160
want_err: "".to_string(),
160161
want_code: 0,
162+
..Default::default()
161163
},
162164
TestItem {
163165
name: "api /user".to_string(),
@@ -213,9 +215,7 @@ async fn test_main(ctx: &mut MainContext) {
213215
"user".to_string(),
214216
"--include".to_string(),
215217
],
216-
want_out: r#"HTTP/2.0 200 OK
217-
access-control-allow-credentials: """#
218-
.to_string(),
218+
want_out: r#"HTTP/2.0 200 OK"#.to_string(),
219219
want_err: "".to_string(),
220220
want_code: 0,
221221
..Default::default()
@@ -452,6 +452,21 @@ access-control-allow-credentials: """#
452452
want_code: 0,
453453
..Default::default()
454454
},
455+
TestItem {
456+
name: "snapshot a kcl assembly as png with .".to_string(),
457+
current_directory: Some(std::env::current_dir().unwrap().join("tests/walkie-talkie")),
458+
args: vec![
459+
"zoo".to_string(),
460+
"kcl".to_string(),
461+
"snapshot".to_string(),
462+
".".to_string(),
463+
"walkie-talkie.png".to_string(),
464+
],
465+
want_out: r#"Snapshot saved to `walkie-talkie.png`"#.to_string(),
466+
want_err: "".to_string(),
467+
want_code: 0,
468+
..Default::default()
469+
},
455470
TestItem {
456471
name: "get the mass of a kcl file".to_string(),
457472
args: vec![
@@ -796,11 +811,19 @@ access-control-allow-credentials: """#
796811
debug: false,
797812
};
798813

814+
let old_current_directory = std::env::current_dir().unwrap();
815+
if let Some(current_directory) = t.current_directory {
816+
std::env::set_current_dir(&current_directory).unwrap();
817+
}
818+
799819
let result = crate::do_main(t.args, &mut ctx).await;
800820

801821
let stdout = std::fs::read_to_string(stdout_path).unwrap_or_default();
802822
let stderr = std::fs::read_to_string(stderr_path).unwrap_or_default();
803823

824+
// Reset the cwd.
825+
std::env::set_current_dir(old_current_directory).unwrap();
826+
804827
assert!(
805828
stdout.contains(&t.want_out),
806829
"test {} ->\nstdout: {}\nwant: {}\n\nstderr: {}",

tests/gear.kcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ holeRadius = 1
8989
startAngle = asin(keywayWidth / 2 / holeRadius)
9090

9191
// Sketch the keyway and center hole and extrude
92-
keyWay = startSketchOn(body, 'END')
92+
keyWay = startSketchOn(body, face = 'END')
9393
|> startProfileAt([
9494
holeRadius * cos(startAngle),
9595
holeRadius * sin(startAngle)

tests/nested-settings/subdir/gear.kcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ holeRadius = 1
8989
startAngle = asin(keywayWidth / 2 / holeRadius)
9090

9191
// Sketch the keyway and center hole and extrude
92-
keyWay = startSketchOn(body, 'END')
92+
keyWay = startSketchOn(body, face = 'END')
9393
|> startProfileAt([
9494
holeRadius * cos(startAngle),
9595
holeRadius * sin(startAngle)

tests/walkie-talkie.png

61 Bytes
Loading

tests/walkie-talkie/antenna.kcl

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,32 @@
1-
@settings(defaultLengthUnit = in)
2-
3-
// Antenna
1+
// Walkie Talkie Antenna
2+
// Antenna for the walkie talkie assembly
43

54
// Set units
5+
@settings(defaultLengthUnit = in)
66

7-
// import constants
8-
import height, width, antennaBaseWidth, antennaBaseHeight, antennaTopWidth, antennaTopHeight from "globals.kcl"
9-
10-
// Calculate the origin
11-
origin = [-width / 2 + .45, -0.10]
12-
13-
// Create the antenna
14-
antennaX = origin[0]
15-
antennaY = origin[1]
16-
17-
antennaPlane = {
18-
plane = {
19-
origin = { x = 0, y = 0, z = height / 2 },
20-
xAxis = { x = 1, y = 0, z = 0 },
21-
yAxis = { x = 0, y = 1, z = 0 },
22-
zAxis = { x = 0, y = 0, z = 1 }
23-
}
24-
}
7+
// Import parameters
8+
import antennaLength, antennaBaseWidth, antennaBaseHeight, antennaTopWidth, antennaTopHeight from "parameters.kcl"
259

2610
// Create the antenna base sketch
27-
sketch001 = startSketchOn(antennaPlane)
28-
|> startProfileAt([origin[0], origin[1]], %)
11+
antennaBaseSketch = startSketchOn(XY)
12+
|> startProfileAt([0, 0], %)
2913
|> line(end = [antennaBaseWidth, 0])
3014
|> line(end = [0, -antennaBaseHeight])
3115
|> line(end = [-antennaBaseWidth, 0])
3216
|> close()
3317

3418
// Create the antenna top sketch
35-
loftPlane = offsetPlane(XY, offset = height / 2 + 3)
36-
37-
sketch002 = startSketchOn(loftPlane)
19+
loftPlane = offsetPlane(XY, offset = antennaLength)
20+
antennaTopSketch = startSketchOn(loftPlane)
3821
|> startProfileAt([
39-
origin[0] + (antennaBaseWidth - antennaTopWidth) / 2,
40-
origin[1] - ((antennaBaseHeight - antennaTopHeight) / 2)
22+
(antennaBaseWidth - antennaTopWidth) / 2,
23+
(antennaBaseHeight - antennaTopHeight) / 2
4124
], %)
4225
|> xLine(length = antennaTopWidth)
4326
|> yLine(length = -antennaTopHeight)
4427
|> xLine(length = -antennaTopWidth)
4528
|> close()
4629

4730
// Create the antenna using a loft
48-
loft([sketch001, sketch002])
31+
loft([antennaBaseSketch, antennaTopSketch])
4932
|> appearance(color = "#000000")

tests/walkie-talkie/body.kcl

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
@settings(defaultLengthUnit = in)
2-
3-
// Walkie talkie body
1+
// Walkie Talkie Body
2+
// The main body of the walkie talkie assembly
43

54
// Set units
5+
@settings(defaultLengthUnit = in)
66

7-
// Import constants
8-
import height, width, thickness, chamferLength, offset, screenWidth, screenHeight, screenYPosition, screenDepth, speakerBoxWidth, speakerBoxHeight from "globals.kcl"
7+
// Import parameters
8+
import height, width, thickness, chamferLength, offset, screenWidth, screenHeight, screenYPosition, screenDepth, speakerBoxWidth, speakerBoxHeight from "parameters.kcl"
99

10-
bodySketch = startSketchOn(XZ)
10+
// Sketch and extrude the body of the walkie talkie
11+
body = startSketchOn(XZ)
1112
|> startProfileAt([-width / 2, height / 2], %)
1213
|> xLine(length = width, tag = $chamfer1)
1314
|> yLine(length = -height, tag = $chamfer2)
1415
|> xLine(length = -width, tag = $chamfer3)
1516
|> close(tag = $chamfer4)
16-
bodyExtrude = extrude(bodySketch, length = thickness)
17+
|> extrude(%, length = thickness)
1718
|> chamfer(
1819
length = chamferLength,
1920
tags = [
@@ -24,53 +25,48 @@ bodyExtrude = extrude(bodySketch, length = thickness)
2425
],
2526
)
2627

27-
// Define the offset for the indentation
28-
sketch002 = startSketchOn(bodyExtrude, 'END')
28+
// Cut out the indentation for the case
29+
caseIndentSketch = startSketchOn(body, face = END)
2930
|> startProfileAt([
3031
-width / 2 + offset,
3132
height / 2 - (chamferLength + offset / 2 * cos(toRadians(45)))
3233
], %)
33-
|> angledLineToY({ angle = 45, to = height / 2 - offset }, %)
34+
|> angledLine(angle = 45, endAbsoluteY = height / 2 - offset)
3435
|> line(endAbsolute = [
3536
width / 2 - (chamferLength + offset / 2 * cos(toRadians(45))),
3637
height / 2 - offset
3738
])
38-
|> angledLineToX({ angle = -45, to = width / 2 - offset }, %)
39+
|> angledLine(angle = -45, endAbsoluteX = width / 2 - offset)
3940
|> line(endAbsolute = [
4041
width / 2 - offset,
4142
-(height / 2 - (chamferLength + offset / 2 * cos(toRadians(45))))
4243
])
43-
|> angledLineToY({
44-
angle = -135,
45-
to = -height / 2 + offset
46-
}, %)
44+
|> angledLine(angle = -135, endAbsoluteY = -height / 2 + offset)
4745
|> line(endAbsolute = [
4846
-(width / 2 - (chamferLength + offset / 2 * cos(toRadians(45)))),
4947
-height / 2 + offset
5048
])
51-
|> angledLineToX({
52-
angle = -225,
53-
to = -width / 2 + offset
54-
}, %)
49+
|> angledLine(angle = -225, endAbsoluteX = -width / 2 + offset)
5550
|> close()
56-
extrude002 = extrude(sketch002, length = -0.0625)
51+
extrude002 = extrude(caseIndentSketch, length = -0.0625)
5752

5853
// Create the pocket for the screen
59-
sketch003 = startSketchOn(extrude002, 'start')
54+
screenCutout = startSketchOn(extrude002, face = START)
6055
|> startProfileAt([-screenWidth / 2, screenYPosition], %)
6156
|> xLine(length = screenWidth, tag = $seg01)
6257
|> yLine(length = -screenHeight)
6358
|> xLine(length = -segLen(seg01))
6459
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
6560
|> close()
66-
extrude003 = extrude(sketch003, length = screenDepth)
61+
extrude003 = extrude(screenCutout, length = screenDepth)
6762

6863
// Create the speaker box
69-
sketch004 = startSketchOn(extrude002, 'start')
64+
speakerBox = startSketchOn(extrude002, face = START)
7065
|> startProfileAt([-1.25 / 2, -.125], %)
7166
|> xLine(length = speakerBoxWidth)
7267
|> yLine(length = -speakerBoxHeight)
7368
|> xLine(length = -speakerBoxWidth)
7469
|> close()
75-
extrude(sketch004, length = -.5)
70+
71+
extrude(speakerBox, length = -.5)
7672
|> appearance(color = "#277bb0")

tests/walkie-talkie/button.kcl

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1+
// Walkie Talkie Button
2+
// Button for the walkie talkie
3+
4+
// Set units
15
@settings(defaultLengthUnit = in)
26

3-
// Walkie Talkie button
7+
// Import parameters
8+
import buttonWidth, buttonHeight, buttonThickness from "parameters.kcl"
49

5-
// Set units
10+
// Create a function for the button. We need to create a function to use multiple buttons.
611

7-
// Import constants
8-
import screenHeight, buttonWidth, tolerance, buttonHeight, buttonThickness from "globals.kcl"
912

10-
// Create a function for the button
11-
export fn button(origin, rotation, plane) {
12-
buttonSketch = startSketchOn(plane)
13-
|> startProfileAt([origin[0], origin[1]], %)
14-
|> angledLine({
15-
angle = 180 + rotation,
16-
length = buttonWidth
17-
}, %, $tag1)
18-
|> angledLine({
19-
angle = 270 + rotation,
20-
length = buttonHeight
21-
}, %, $tag2)
22-
|> angledLine({
23-
angle = 0 + rotation,
24-
length = buttonWidth
25-
}, %)
13+
export fn button() {
14+
// Sketch the button profile and extrude
15+
buttonSketch = startSketchOn(XZ)
16+
|> startProfileAt([0, 0], %)
17+
|> angledLine(angle = 180, length = buttonWidth, tag = $tag1)
18+
|> angledLine(angle = 270, length = buttonHeight, tag = $tag2)
19+
|> angledLine(angle = 0, length = buttonWidth)
2620
|> close()
27-
buttonExtrude = extrude(buttonSketch, length = buttonThickness)
21+
button = extrude(buttonSketch, length = buttonThickness)
2822
|> chamfer(
2923
length = .050,
3024
tags = [
@@ -34,5 +28,5 @@ export fn button(origin, rotation, plane) {
3428
)
3529
|> appearance(color = "#ff0000")
3630

37-
return buttonExtrude
31+
return button
3832
}

0 commit comments

Comments
 (0)