Skip to content

Commit

Permalink
Add error test for doc diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
wawel37 committed Oct 14, 2024
1 parent e8c2a69 commit 02e96d6
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions extensions/scarb-doc/tests/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,140 @@ fn test_diagnostics_not_allowed_warnings() {
.assert()
.success();
}

#[test]
fn test_diagnostics_error() {
let t = TempDir::new().unwrap();

ProjectBuilder::start()
.name("hello_world")
.lib_cairo(indoc! {r#"
#[starknet::contract]
pub(crate) mod DualCaseERC20Mock {
use starknet::ContractAddress;
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
#[storage]
pub struct Storage {
#[substorage(v0)]
pub erc20: ERC20Component::Storage
}
#[event]
enum Event {
#[flat]
ERC20Event: ERC20Component::Event
}
}
}
"#})
.build(&t);

let snapbox = Scarb::quick_snapbox()
.arg("doc")
.current_dir(&t)
.assert()
.failure();

#[cfg(windows)]
snapbox.stdout_matches(indoc! {r#"
error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/Impl/InlineMacro/Module/Struct/Trait/TypeAlias/Use or an attribute.
--> [..]
}
^
error: Identifier not found.
--> [..]
ERC20Event: ERC20Component::Event
^************^
error: Identifier not found.
--> [..]
pub erc20: ERC20Component::Storage
^************^
error: Type annotations needed. Failed to infer ?0.
--> [..]
#[storage]
^********^
error: Invalid drop trait implementation, Trait `core::traits::Drop::<<missing>>` has multiple implementations, in: `hello_world::DualCaseERC20Mock::ContractStateDrop`, `hello_world::DualCaseERC20Mock::StorageStorageBaseDrop`
--> [..]
#[storage]
^********^
error: Trait has no implementation in context: core::starknet::event::Event::<hello_world::DualCaseERC20Mock::Event>.
--> [..]
#[starknet::contract]
^*******************^
error: Identifier not found.
--> [..]
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
^************^
error: Invalid drop trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageDrop::<?0> has an unused generic parameter.
--> [..]
#[storage]
^********^
error: Invalid copy trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageCopy::<?0> has an unused generic parameter.
--> [..]
#[storage]
^********^
error: Compilation failed.
error: process did not exit successfully: exit code: 1
"#});

#[cfg(not(windows))]
snapbox.stdout_matches(indoc! {r#"
error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/Impl/InlineMacro/Module/Struct/Trait/TypeAlias/Use or an attribute.
--> [..]
}
^
error: Identifier not found.
--> [..]
ERC20Event: ERC20Component::Event
^************^
error: Identifier not found.
--> [..]
pub erc20: ERC20Component::Storage
^************^
error: Type annotations needed. Failed to infer ?0.
--> [..]
#[storage]
^********^
error: Invalid drop trait implementation, Trait `core::traits::Drop::<<missing>>` has multiple implementations, in: `hello_world::DualCaseERC20Mock::ContractStateDrop`, `hello_world::DualCaseERC20Mock::StorageStorageBaseDrop`
--> [..]
#[storage]
^********^
error: Trait has no implementation in context: core::starknet::event::Event::<hello_world::DualCaseERC20Mock::Event>.
--> [..]
#[starknet::contract]
^*******************^
error: Identifier not found.
--> [..]
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
^************^
error: Invalid drop trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageDrop::<?0> has an unused generic parameter.
--> [..]
#[storage]
^********^
error: Invalid copy trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageCopy::<?0> has an unused generic parameter.
--> [..]
#[storage]
^********^
error: Compilation failed.
"#});
}

0 comments on commit 02e96d6

Please sign in to comment.