From fc19206029b14042b9fdac6ed03b92223c9d115f Mon Sep 17 00:00:00 2001 From: Niklas Mohrin Date: Wed, 1 Jan 2025 23:17:49 +0100 Subject: [PATCH] Add `ignore-online-tests` feature Since these tests require internet access, they are undesirable in reproducible builds [1] (and in general, I guess). The overall goal is to shrink this list to a minimum. At some point we might remove the feature again and ignore online tests by default. Before putting much thought into refactoring the remaining tests, we should wait until we have introduced the `updates.archive_url` option. Then, we could run a local webserver that serves a known file. Until then, having the feature already helps discourage using `--update` in tests that don't need it and allows for quicker test execution locally if wanted. - [1]: https://github.com/NixOS/nixpkgs/blob/edf04b75c13c2ac0e54df5ec5c543e300f76f1c9/pkgs/by-name/te/tealdeer/package.nix#L34-L44 --- Cargo.toml | 2 ++ tests/lib.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa1f423..bd0d07a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,8 @@ native-roots = ["reqwest/rustls-tls-native-roots"] webpki-roots = ["reqwest/rustls-tls-webpki-roots"] native-tls = ["reqwest/native-tls"] +ignore-online-tests = [] + [profile.release] strip = true opt-level = 3 diff --git a/tests/lib.rs b/tests/lib.rs index 99e736f..fc99688 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -186,6 +186,7 @@ fn test_missing_cache() { .stderr(contains("Page cache not found. Please run `tldr --update`")); } +#[cfg_attr(feature = "ignore-online-tests", ignore = "online test")] #[test] fn test_update_cache_default_features() { let testenv = TestEnv::new(); @@ -207,6 +208,7 @@ fn test_update_cache_default_features() { testenv.command().args(["sl"]).assert().success(); } +#[cfg_attr(feature = "ignore-online-tests", ignore = "online test")] #[test] fn test_update_cache_rustls_webpki() { let testenv = TestEnv::new() @@ -230,6 +232,7 @@ fn test_update_cache_rustls_webpki() { testenv.command().args(["sl"]).assert().success(); } +#[cfg_attr(feature = "ignore-online-tests", ignore = "online test")] #[test] fn test_quiet_cache() { let testenv = TestEnv::new(); @@ -285,6 +288,7 @@ fn test_quiet_old_cache() { .stderr(contains("The cache hasn't been updated for ").not()); } +#[cfg_attr(feature = "ignore-online-tests", ignore = "online test")] #[test] fn test_create_cache_directory_path() { let testenv = TestEnv::new(); @@ -297,7 +301,7 @@ fn test_create_cache_directory_path() { assert!(!internal_cache_dir.exists()); command - .arg("-u") + .arg("--update") .assert() .success() .stderr(contains(format!( @@ -309,6 +313,7 @@ fn test_create_cache_directory_path() { assert!(internal_cache_dir.is_dir()); } +#[cfg_attr(feature = "ignore-online-tests", ignore = "online test")] #[test] fn test_cache_location_not_a_directory() { let testenv = TestEnv::new(); @@ -320,7 +325,7 @@ fn test_cache_location_not_a_directory() { command.env(CACHE_DIR_ENV_VAR, internal_file.to_str().unwrap()); command - .arg("-u") + .arg("--update") .assert() .failure() .stderr(contains(format!( @@ -743,6 +748,7 @@ fn test_multi_platform_list_flag_rendering() { .stdout("common\ndel\ndir\nls\nrm\nwinux\n"); } +#[cfg_attr(feature = "ignore-online-tests", ignore = "online test")] #[test] fn test_autoupdate_cache() { let testenv = TestEnv::new();