@@ -35,6 +35,59 @@ fn clean_all() -> Result<()> {
3535 Ok ( ( ) )
3636}
3737
38+ #[ test]
39+ fn clean_force ( ) -> Result < ( ) > {
40+ let context = TestContext :: new ( "3.12" ) . with_filtered_counts ( ) ;
41+
42+ let requirements_txt = context. temp_dir . child ( "requirements.txt" ) ;
43+ requirements_txt. write_str ( "typing-extensions\n iniconfig" ) ?;
44+
45+ // Install a requirement, to populate the cache.
46+ context
47+ . pip_sync ( )
48+ . arg ( "requirements.txt" )
49+ . assert ( )
50+ . success ( ) ;
51+
52+ // When unlocked, `--force` should still take a lock
53+ uv_snapshot ! ( context. filters( ) , context. clean( ) . arg( "--verbose" ) . arg( "--force" ) , @r"
54+ success: true
55+ exit_code: 0
56+ ----- stdout -----
57+
58+ ----- stderr -----
59+ DEBUG uv [VERSION] ([COMMIT] DATE)
60+ DEBUG Acquired lock for `[CACHE_DIR]/`
61+ Clearing cache at: [CACHE_DIR]/
62+ DEBUG Released lock at `[CACHE_DIR]/.lock`
63+ Removed [N] files ([SIZE])
64+ " ) ;
65+
66+ // Install a requirement, to re-populate the cache.
67+ context
68+ . pip_sync ( )
69+ . arg ( "requirements.txt" )
70+ . assert ( )
71+ . success ( ) ;
72+
73+ // When locked, `--force` should proceed without blocking
74+ let _cache = uv_cache:: Cache :: from_path ( & context. cache_dir . path ( ) ) . with_exclusive_lock ( ) ;
75+ uv_snapshot ! ( context. filters( ) , context. clean( ) . arg( "--verbose" ) . arg( "--force" ) , @r"
76+ success: true
77+ exit_code: 0
78+ ----- stdout -----
79+
80+ ----- stderr -----
81+ DEBUG uv [VERSION] ([COMMIT] DATE)
82+ DEBUG Lock is busy for `[CACHE_DIR]/`
83+ DEBUG Cache is currently in use, proceeding due to `--force`
84+ Clearing cache at: [CACHE_DIR]/
85+ Removed [N] files ([SIZE])
86+ " ) ;
87+
88+ Ok ( ( ) )
89+ }
90+
3891/// `cache clean iniconfig` should remove a single package (`iniconfig`).
3992#[ test]
4093fn clean_package_pypi ( ) -> Result < ( ) > {
0 commit comments