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.6 kB 217 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 57// There are 2 separate tests for Windows and for Unix, because on Windows note 58// about inability to create symlinks without Developer Mode is shown, so 59// snapshots differ. 60 61#[cfg(windows)] 62#[test] 63fn io_link_file_error_windows() { 64 let error = Error::FileIo { 65 kind: FileKind::File, 66 action: FileIoAction::Link("/dest".into()), 67 path: "/src".into(), 68 err: Some("Critical error!".to_owned()), 69 } 70 .pretty_string(); 71 assert_snapshot!(error); 72} 73 74#[cfg(not(windows))] 75#[test] 76fn io_link_file_error_not_windows() { 77 let error = Error::FileIo { 78 kind: FileKind::File, 79 action: FileIoAction::Link("/dest".into()), 80 path: "/src".into(), 81 err: Some("Critical error!".to_owned()), 82 } 83 .pretty_string(); 84 assert_snapshot!(error); 85} 86 87#[test] 88fn io_copy_directory_error() { 89 let error = Error::FileIo { 90 kind: FileKind::Directory, 91 action: FileIoAction::Copy(Some("/dest".into())), 92 path: "/src".into(), 93 err: Some("Critical error!".to_owned()), 94 } 95 .pretty_string(); 96 assert_snapshot!(error); 97} 98 99#[test] 100fn io_delete_file_error() { 101 let error = Error::FileIo { 102 kind: FileKind::File, 103 action: FileIoAction::Delete, 104 path: "/file".into(), 105 err: Some("Critical error!".to_owned()), 106 } 107 .pretty_string(); 108 assert_snapshot!(error); 109} 110 111#[test] 112fn io_open_file_error() { 113 let error = Error::FileIo { 114 kind: FileKind::File, 115 action: FileIoAction::Open, 116 path: "/file".into(), 117 err: Some("Critical error!".to_owned()), 118 } 119 .pretty_string(); 120 assert_snapshot!(error); 121} 122 123#[test] 124fn io_parse_file_error() { 125 let error = Error::FileIo { 126 kind: FileKind::File, 127 action: FileIoAction::Parse, 128 path: "/file".into(), 129 err: Some("Critical error!".to_owned()), 130 } 131 .pretty_string(); 132 assert_snapshot!(error); 133} 134 135#[test] 136fn io_read_file_error() { 137 let error = Error::FileIo { 138 kind: FileKind::File, 139 action: FileIoAction::Read, 140 path: "/file".into(), 141 err: Some("Critical error!".to_owned()), 142 } 143 .pretty_string(); 144 assert_snapshot!(error); 145} 146 147#[test] 148fn io_create_directory_error() { 149 let error = Error::FileIo { 150 kind: FileKind::Directory, 151 action: FileIoAction::Create, 152 path: "/dir".into(), 153 err: Some("Critical error!".to_owned()), 154 } 155 .pretty_string(); 156 assert_snapshot!(error); 157} 158 159#[test] 160fn io_write_to_file_error() { 161 let error = Error::FileIo { 162 kind: FileKind::File, 163 action: FileIoAction::WriteTo, 164 path: "/file".into(), 165 err: Some("Critical error!".to_owned()), 166 } 167 .pretty_string(); 168 assert_snapshot!(error); 169} 170 171#[test] 172fn io_find_parent_of_directory_error() { 173 let error = Error::FileIo { 174 kind: FileKind::Directory, 175 action: FileIoAction::FindParent, 176 path: "/dir".into(), 177 err: Some("Critical error!".to_owned()), 178 } 179 .pretty_string(); 180 assert_snapshot!(error); 181} 182 183#[test] 184fn io_canonicalise_file_error() { 185 let error = Error::FileIo { 186 kind: FileKind::File, 187 action: FileIoAction::Canonicalise, 188 path: "/file".into(), 189 err: Some("Critical error!".to_owned()), 190 } 191 .pretty_string(); 192 assert_snapshot!(error); 193} 194 195#[test] 196fn io_update_file_permissions_error() { 197 let error = Error::FileIo { 198 kind: FileKind::File, 199 action: FileIoAction::UpdatePermissions, 200 path: "/file".into(), 201 err: Some("Critical error!".to_owned()), 202 } 203 .pretty_string(); 204 assert_snapshot!(error); 205} 206 207#[test] 208fn io_read_metadata_of_file_error() { 209 let error = Error::FileIo { 210 kind: FileKind::File, 211 action: FileIoAction::ReadMetadata, 212 path: "/file".into(), 213 err: Some("Critical error!".to_owned()), 214 } 215 .pretty_string(); 216 assert_snapshot!(error); 217}