Skip to content

Commit 65e3f8e

Browse files
committed
Add more e2e tests
1 parent b1d45cf commit 65e3f8e

3 files changed

Lines changed: 84 additions & 6 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "not a Sierra contract class"
3+
}

crates/forge/tests/data/declare_from_file/tests/tests.cairo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ fn already_declared() {
2424
_ => panic!("expected AlreadyDeclared"),
2525
}
2626
}
27+
28+
#[test]
29+
fn missing_file() {
30+
declare_from_file("data/missing.contract_class.json").unwrap();
31+
}
32+
33+
#[test]
34+
fn invalid_json() {
35+
declare_from_file("data/invalid_contract_class.json").unwrap();
36+
}

crates/forge/tests/e2e/declare_from_file.rs

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use shared::test_utils::output_assert::assert_stdout_contains;
55
use snapbox::cmd::Command as SnapboxCommand;
66

77
#[test]
8-
fn declare_from_file() {
8+
fn simple() {
99
let temp = setup_package("declare_from_file");
1010

1111
SnapboxCommand::from_std(
@@ -17,21 +17,86 @@ fn declare_from_file() {
1717
.assert()
1818
.success();
1919

20-
let output = test_runner(&temp).assert().success();
20+
let output = test_runner(&temp).arg("simple").assert().success();
2121

2222
assert_stdout_contains(
2323
output,
2424
indoc! {r"
2525
[..]Compiling[..]
2626
[..]Finished[..]
2727
28-
29-
Collected 2 test(s) from declare_from_file package
28+
Collected 1 test(s) from declare_from_file package
3029
Running 0 test(s) from src/
31-
Running 2 test(s) from tests/
30+
Running 1 test(s) from tests/
3231
[PASS] declare_from_file_integrationtest::tests::simple [..]
32+
Tests: 1 passed, 0 failed, 0 ignored, 1 filtered out
33+
"},
34+
);
35+
}
36+
37+
#[test]
38+
fn already_declared() {
39+
let temp = setup_package("declare_from_file");
40+
41+
SnapboxCommand::from_std(
42+
ScarbCommand::new()
43+
.current_dir(temp.path())
44+
.arg("build")
45+
.command(),
46+
)
47+
.assert()
48+
.success();
49+
50+
let output = test_runner(&temp)
51+
.arg("already_declared")
52+
.assert()
53+
.success();
54+
55+
assert_stdout_contains(
56+
output,
57+
indoc! {r"
58+
[..]Compiling[..]
59+
[..]Finished[..]
60+
61+
Collected 1 test(s) from declare_from_file package
62+
Running 0 test(s) from src/
63+
Running 1 test(s) from tests/
3364
[PASS] declare_from_file_integrationtest::tests::already_declared [..]
34-
Tests: 2 passed, 0 failed, 0 ignored, 0 filtered out
65+
Tests: 1 passed, 0 failed, 0 ignored, 1 filtered out
3566
"},
3667
);
3768
}
69+
70+
#[test]
71+
fn missing_file() {
72+
let temp = setup_package("declare_from_file_failures");
73+
74+
let output = test_runner(&temp).arg("missing_file").assert().code(1);
75+
76+
assert_stdout_contains(
77+
output,
78+
indoc! {r#"
79+
[FAIL] declare_from_file_failures_integrationtest::tests::missing_file
80+
81+
Failure data:
82+
"Failed to read Sierra file at data/missing.contract_class.json: [..]"
83+
"#},
84+
);
85+
}
86+
87+
#[test]
88+
fn invalid_json() {
89+
let temp = setup_package("declare_from_file_failures");
90+
91+
let output = test_runner(&temp).arg("invalid_json").assert().code(1);
92+
93+
assert_stdout_contains(
94+
output,
95+
indoc! {r#"
96+
[FAIL] declare_from_file_failures_integrationtest::tests::invalid_json
97+
98+
Failure data:
99+
"Failed to parse Sierra contract class JSON at data/invalid_contract_class.json: [..]"
100+
"#},
101+
);
102+
}

0 commit comments

Comments
 (0)