Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / compiler-core / src / error / tests.rs
5.0 kB 198 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2024 The Gleam contributors 3 4use super::*; 5use insta::assert_debug_snapshot; 6use insta::assert_snapshot; 7 8#[test] 9fn test_shell_program_not_found_error() { 10 let cmds = vec!["erlc", "rebar3", "deno", "elixir", "node", "bun", "git"]; 11 let oses = vec!["macos", "linux"]; 12 let distros = vec!["ubuntu", "other"]; 13 14 for cmd in &cmds { 15 for os in &oses { 16 if os != &"linux" { 17 let err = Error::ShellProgramNotFound { 18 program: cmd.to_string(), 19 os: parse_os(os, "other"), 20 } 21 .to_diagnostics(); 22 assert_snapshot!( 23 format!("shell_program_not_found_{cmd}_{os}_other"), 24 err[0].text 25 ); 26 } else { 27 for distro in &distros { 28 let err = Error::ShellProgramNotFound { 29 program: cmd.to_string(), 30 os: parse_os(os, distro), 31 } 32 .to_diagnostics(); 33 assert_snapshot!( 34 format!("shell_program_not_found_{cmd}_{os}_{distro}"), 35 err[0].text 36 ); 37 } 38 } 39 } 40 } 41} 42 43#[test] 44fn hex_session_revoked() { 45 let err = Error::HexSessionRevoked.to_diagnostics(); 46 assert_debug_snapshot!(err[0]); 47} 48 49#[test] 50fn hex_error_conversion() { 51 assert_eq!( 52 Error::hex(hexpm::ApiError::OAuthRefreshTokenRejected), 53 Error::HexSessionRevoked 54 ); 55} 56 57fn io_link_file_error() { 58 let error = Error::FileIo { 59 kind: FileKind::File, 60 action: FileIoAction::Link("/dest".into()), 61 path: "/src".into(), 62 err: Some("Critical error!".to_owned()), 63 } 64 .pretty_string(); 65 assert_snapshot!(error); 66} 67 68#[test] 69fn io_copy_directory_error() { 70 let error = Error::FileIo { 71 kind: FileKind::Directory, 72 action: FileIoAction::Copy("/dest".into()), 73 path: "/src".into(), 74 err: Some("Critical error!".to_owned()), 75 } 76 .pretty_string(); 77 assert_snapshot!(error); 78} 79 80#[test] 81fn io_delete_file_error() { 82 let error = Error::FileIo { 83 kind: FileKind::File, 84 action: FileIoAction::Delete, 85 path: "/file".into(), 86 err: Some("Critical error!".to_owned()), 87 } 88 .pretty_string(); 89 assert_snapshot!(error); 90} 91 92#[test] 93fn io_open_file_error() { 94 let error = Error::FileIo { 95 kind: FileKind::File, 96 action: FileIoAction::Open, 97 path: "/file".into(), 98 err: Some("Critical error!".to_owned()), 99 } 100 .pretty_string(); 101 assert_snapshot!(error); 102} 103 104#[test] 105fn io_parse_file_error() { 106 let error = Error::FileIo { 107 kind: FileKind::File, 108 action: FileIoAction::Parse, 109 path: "/file".into(), 110 err: Some("Critical error!".to_owned()), 111 } 112 .pretty_string(); 113 assert_snapshot!(error); 114} 115 116#[test] 117fn io_read_file_error() { 118 let error = Error::FileIo { 119 kind: FileKind::File, 120 action: FileIoAction::Read, 121 path: "/file".into(), 122 err: Some("Critical error!".to_owned()), 123 } 124 .pretty_string(); 125 assert_snapshot!(error); 126} 127 128#[test] 129fn io_create_directory_error() { 130 let error = Error::FileIo { 131 kind: FileKind::Directory, 132 action: FileIoAction::Create, 133 path: "/dir".into(), 134 err: Some("Critical error!".to_owned()), 135 } 136 .pretty_string(); 137 assert_snapshot!(error); 138} 139 140#[test] 141fn io_write_to_file_error() { 142 let error = Error::FileIo { 143 kind: FileKind::File, 144 action: FileIoAction::WriteTo, 145 path: "/file".into(), 146 err: Some("Critical error!".to_owned()), 147 } 148 .pretty_string(); 149 assert_snapshot!(error); 150} 151 152#[test] 153fn io_find_parent_of_directory_error() { 154 let error = Error::FileIo { 155 kind: FileKind::Directory, 156 action: FileIoAction::FindParent, 157 path: "/dir".into(), 158 err: Some("Critical error!".to_owned()), 159 } 160 .pretty_string(); 161 assert_snapshot!(error); 162} 163 164#[test] 165fn io_canonicalise_file_error() { 166 let error = Error::FileIo { 167 kind: FileKind::File, 168 action: FileIoAction::Canonicalise, 169 path: "/file".into(), 170 err: Some("Critical error!".to_owned()), 171 } 172 .pretty_string(); 173 assert_snapshot!(error); 174} 175 176#[test] 177fn io_update_file_permissions_error() { 178 let error = Error::FileIo { 179 kind: FileKind::File, 180 action: FileIoAction::UpdatePermissions, 181 path: "/file".into(), 182 err: Some("Critical error!".to_owned()), 183 } 184 .pretty_string(); 185 assert_snapshot!(error); 186} 187 188#[test] 189fn io_read_metadata_of_file_error() { 190 let error = Error::FileIo { 191 kind: FileKind::File, 192 action: FileIoAction::ReadMetadata, 193 path: "/file".into(), 194 err: Some("Critical error!".to_owned()), 195 } 196 .pretty_string(); 197 assert_snapshot!(error); 198}