From 02e96d6ab77c8b95676e14c901eb019b74a0b233 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Mon, 14 Oct 2024 11:44:36 +0200 Subject: [PATCH] Add error test for doc diagnostics --- extensions/scarb-doc/tests/diagnostics.rs | 137 ++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index de0fdebe9..04d040100 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -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::<>` has multiple implementations, in: `hello_world::DualCaseERC20Mock::ContractStateDrop`, `hello_world::DualCaseERC20Mock::StorageStorageBaseDrop` + --> [..] + #[storage] + ^********^ + + error: Trait has no implementation in context: core::starknet::event::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:: has an unused generic parameter. + --> [..] + #[storage] + ^********^ + + error: Invalid copy trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageCopy:: 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::<>` has multiple implementations, in: `hello_world::DualCaseERC20Mock::ContractStateDrop`, `hello_world::DualCaseERC20Mock::StorageStorageBaseDrop` + --> [..] + #[storage] + ^********^ + + error: Trait has no implementation in context: core::starknet::event::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:: has an unused generic parameter. + --> [..] + #[storage] + ^********^ + + error: Invalid copy trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageCopy:: has an unused generic parameter. + --> [..] + #[storage] + ^********^ + + error: Compilation failed. + "#}); +}