My agentic slop goes here. Not intended for anyone else!
at jsont 4.6 kB view raw
1let test_path_validation () = 2 Printf.printf "Testing XDG path validation...\n"; 3 (* Test absolute path validation for environment variables *) 4 let test_relative_path_rejection env_var relative_path = 5 Printf.printf "Testing rejection of relative path in %s...\n" env_var; 6 Unix.putenv env_var relative_path; 7 try 8 Eio_main.run 9 @@ fun env -> 10 let _ = Xdge.create env#fs "test_validation" in 11 Printf.printf "ERROR: Should have rejected relative path\n"; 12 false 13 with 14 | Xdge.Invalid_xdg_path msg -> 15 Printf.printf "SUCCESS: Correctly rejected relative path: %s\n" msg; 16 true 17 | exn -> 18 Printf.printf "ERROR: Wrong exception: %s\n" (Printexc.to_string exn); 19 false 20 in 21 let old_config_home = Sys.getenv_opt "XDG_CONFIG_HOME" in 22 let old_data_dirs = Sys.getenv_opt "XDG_DATA_DIRS" in 23 let success1 = test_relative_path_rejection "XDG_CONFIG_HOME" "relative/path" in 24 let success2 = test_relative_path_rejection "XDG_DATA_DIRS" "rel1:rel2:/abs/path" in 25 (* Restore original env vars *) 26 (match old_config_home with 27 | Some v -> Unix.putenv "XDG_CONFIG_HOME" v 28 | None -> 29 (try Unix.putenv "XDG_CONFIG_HOME" "" with 30 | _ -> ())); 31 (match old_data_dirs with 32 | Some v -> Unix.putenv "XDG_DATA_DIRS" v 33 | None -> 34 (try Unix.putenv "XDG_DATA_DIRS" "" with 35 | _ -> ())); 36 success1 && success2 37;; 38 39let test_file_search () = 40 Printf.printf "\nTesting XDG file search...\n"; 41 Eio_main.run 42 @@ fun env -> 43 let xdg = Xdge.create env#fs "search_test" in 44 (* Create test files *) 45 let config_file = Eio.Path.(Xdge.config_dir xdg / "test.conf") in 46 let data_file = Eio.Path.(Xdge.data_dir xdg / "test.dat") in 47 Eio.Path.save ~create:(`Or_truncate 0o644) config_file "config content"; 48 Eio.Path.save ~create:(`Or_truncate 0o644) data_file "data content"; 49 (* Test finding existing files *) 50 (match Xdge.find_config_file xdg "test.conf" with 51 | Some path -> 52 let content = Eio.Path.load path in 53 Printf.printf "Found config file: %s\n" (String.trim content) 54 | None -> Printf.printf "ERROR: Config file not found\n"); 55 (match Xdge.find_data_file xdg "test.dat" with 56 | Some path -> 57 let content = Eio.Path.load path in 58 Printf.printf "Found data file: %s\n" (String.trim content) 59 | None -> Printf.printf "ERROR: Data file not found\n"); 60 (* Test non-existent file *) 61 match Xdge.find_config_file xdg "nonexistent.conf" with 62 | Some _ -> Printf.printf "ERROR: Should not have found nonexistent file\n" 63 | None -> Printf.printf "Correctly handled nonexistent file\n" 64;; 65 66let () = 67 (* Check if we should run validation tests *) 68 if Array.length Sys.argv > 1 && Sys.argv.(1) = "--validate" 69 then ( 70 let validation_success = test_path_validation () in 71 test_file_search (); 72 if validation_success 73 then Printf.printf "\nAll path validation tests passed!\n" 74 else Printf.printf "\nSome validation tests failed!\n") 75 else 76 (* Run original simple functionality test *) 77 Eio_main.run 78 @@ fun env -> 79 let xdg = Xdge.create env#fs "path_test" in 80 (* Test config subdirectory *) 81 let profiles_path = Eio.Path.(Xdge.config_dir xdg / "profiles") in 82 let profile_file = Eio.Path.(profiles_path / "default.json") in 83 (try 84 let content = Eio.Path.load profile_file in 85 Printf.printf "config file content: %s" (String.trim content) 86 with 87 | exn -> Printf.printf "config file error: %s" (Printexc.to_string exn)); 88 (* Test data subdirectory *) 89 let db_path = Eio.Path.(Xdge.data_dir xdg / "databases") in 90 let db_file = Eio.Path.(db_path / "main.db") in 91 (try 92 let content = Eio.Path.load db_file in 93 Printf.printf "\ndata file content: %s" (String.trim content) 94 with 95 | exn -> Printf.printf "\ndata file error: %s" (Printexc.to_string exn)); 96 (* Test cache subdirectory *) 97 let cache_path = Eio.Path.(Xdge.cache_dir xdg / "thumbnails") in 98 let cache_file = Eio.Path.(cache_path / "thumb1.png") in 99 (try 100 let content = Eio.Path.load cache_file in 101 Printf.printf "\ncache file content: %s" (String.trim content) 102 with 103 | exn -> Printf.printf "\ncache file error: %s" (Printexc.to_string exn)); 104 (* Test state subdirectory *) 105 let logs_path = Eio.Path.(Xdge.state_dir xdg / "logs") in 106 let log_file = Eio.Path.(logs_path / "app.log") in 107 try 108 let content = Eio.Path.load log_file in 109 Printf.printf "\nstate file content: %s\n" (String.trim content) 110 with 111 | exn -> Printf.printf "\nstate file error: %s\n" (Printexc.to_string exn) 112;;