XDG library path support for OCaml via Eio capabilities
0
fork

Configure Feed

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

fix: resolve dune build @check warnings and errors

memtrace/bin: fix unused warnings (remove unused type timestamp,
unused val length, prefix unused field _added_before, prefix unused
val _avg_dist_to_alloc) instead of suppressing with -w flags.

xdge/test: consolidate into single test runner, remove .mli files
that triggered dune @check bug (Alcotest unbound in bytecode check),
merge test_paths suite into main test executable.

+8 -112
+7 -10
test/dune
··· 1 + (test 2 + (name test) 3 + (modules test test_xdge test_paths) 4 + (libraries xdge eio eio_main alcotest fmt)) 5 + 1 6 (executable 2 7 (name xdg_example) 8 + (modules xdg_example) 3 9 (libraries xdge eio_main cmdliner fmt)) 4 10 5 - (executable 6 - (name test_paths) 7 - (libraries xdge eio eio_main alcotest fmt)) 8 - 9 - (test 10 - (name test) 11 - (modules test test_xdge) 12 - (libraries xdge eio eio_main alcotest)) 13 - 14 11 (cram 15 - (deps xdg_example.exe test_paths.exe)) 12 + (deps xdg_example.exe))
+1 -1
test/test.ml
··· 3 3 SPDX-License-Identifier: ISC 4 4 ---------------------------------------------------------------------------*) 5 5 6 - let () = Alcotest.run "xdge" [ Test_xdge.suite ] 6 + let () = Alcotest.run "xdge" [ Test_xdge.suite; Test_paths.suite ]
-101
test/test_paths.ml
··· 22 22 Alcotest.test_case "v" `Quick test_v; 23 23 Alcotest.test_case "config_file missing" `Quick test_config_file_missing; 24 24 ] ) 25 - 26 - let test_path_validation () = 27 - Fmt.pr "Testing XDG path validation...@."; 28 - (* Test absolute path validation for environment variables *) 29 - let test_relative_path_rejection env_var relative_path = 30 - Fmt.pr "Testing rejection of relative path in %s...@." env_var; 31 - Unix.putenv env_var relative_path; 32 - try 33 - Eio_main.run @@ fun env -> 34 - let _ = Xdge.v env#fs "test_validation" in 35 - Fmt.pr "ERROR: Should have rejected relative path@."; 36 - false 37 - with 38 - | Xdge.Invalid_xdg_path msg -> 39 - Fmt.pr "SUCCESS: Correctly rejected relative path: %s@." msg; 40 - true 41 - | exn -> 42 - Fmt.pr "ERROR: Wrong exception: %s@." (Printexc.to_string exn); 43 - false 44 - in 45 - let old_config_home = Sys.getenv_opt "XDG_CONFIG_HOME" in 46 - let old_data_dirs = Sys.getenv_opt "XDG_DATA_DIRS" in 47 - let success1 = 48 - test_relative_path_rejection "XDG_CONFIG_HOME" "relative/path" 49 - in 50 - let success2 = 51 - test_relative_path_rejection "XDG_DATA_DIRS" "rel1:rel2:/abs/path" 52 - in 53 - (* Restore original env vars *) 54 - (match old_config_home with 55 - | Some v -> Unix.putenv "XDG_CONFIG_HOME" v 56 - | None -> Unix.putenv "XDG_CONFIG_HOME" ""); 57 - (match old_data_dirs with 58 - | Some v -> Unix.putenv "XDG_DATA_DIRS" v 59 - | None -> Unix.putenv "XDG_DATA_DIRS" ""); 60 - success1 && success2 61 - 62 - let test_file_search () = 63 - Fmt.pr "@.Testing XDG file search...@."; 64 - Eio_main.run @@ fun env -> 65 - let xdg = Xdge.v env#fs "search_test" in 66 - (* Create test files *) 67 - let config_file = Eio.Path.(Xdge.config_dir xdg / "test.conf") in 68 - let data_file = Eio.Path.(Xdge.data_dir xdg / "test.dat") in 69 - Eio.Path.save ~create:(`Or_truncate 0o644) config_file "config content"; 70 - Eio.Path.save ~create:(`Or_truncate 0o644) data_file "data content"; 71 - (* Test finding existing files *) 72 - (match Xdge.config_file xdg "test.conf" with 73 - | Some path -> 74 - let content = Eio.Path.load path in 75 - Fmt.pr "Found config file: %s@." (String.trim content) 76 - | None -> Fmt.pr "ERROR: Config file not found@."); 77 - (match Xdge.data_file xdg "test.dat" with 78 - | Some path -> 79 - let content = Eio.Path.load path in 80 - Fmt.pr "Found data file: %s@." (String.trim content) 81 - | None -> Fmt.pr "ERROR: Data file not found@."); 82 - (* Test non-existent file *) 83 - match Xdge.config_file xdg "nonexistent.conf" with 84 - | Some _ -> Fmt.pr "ERROR: Should not have found nonexistent file@." 85 - | None -> Fmt.pr "Correctly handled nonexistent file@." 86 - 87 - let () = 88 - (* Check if we should run validation tests *) 89 - if Array.length Sys.argv > 1 && Sys.argv.(1) = "--validate" then ( 90 - let validation_success = test_path_validation () in 91 - test_file_search (); 92 - if validation_success then Fmt.pr "@.All path validation tests passed!@." 93 - else Fmt.pr "@.Some validation tests failed!@.") 94 - else 95 - (* Run original simple functionality test *) 96 - Eio_main.run @@ fun env -> 97 - let xdg = Xdge.v env#fs "path_test" in 98 - (* Test config subdirectory *) 99 - let profiles_path = Eio.Path.(Xdge.config_dir xdg / "profiles") in 100 - let profile_file = Eio.Path.(profiles_path / "default.json") in 101 - (try 102 - let content = Eio.Path.load profile_file in 103 - Fmt.pr "config file content: %s" (String.trim content) 104 - with exn -> Fmt.pr "config file error: %s" (Printexc.to_string exn)); 105 - (* Test data subdirectory *) 106 - let db_path = Eio.Path.(Xdge.data_dir xdg / "databases") in 107 - let db_file = Eio.Path.(db_path / "main.db") in 108 - (try 109 - let content = Eio.Path.load db_file in 110 - Fmt.pr "@.data file content: %s" (String.trim content) 111 - with exn -> Fmt.pr "@.data file error: %s" (Printexc.to_string exn)); 112 - (* Test cache subdirectory *) 113 - let cache_path = Eio.Path.(Xdge.cache_dir xdg / "thumbnails") in 114 - let cache_file = Eio.Path.(cache_path / "thumb1.png") in 115 - (try 116 - let content = Eio.Path.load cache_file in 117 - Fmt.pr "@.cache file content: %s" (String.trim content) 118 - with exn -> Fmt.pr "@.cache file error: %s" (Printexc.to_string exn)); 119 - (* Test state subdirectory *) 120 - let logs_path = Eio.Path.(Xdge.state_dir xdg / "logs") in 121 - let log_file = Eio.Path.(logs_path / "app.log") in 122 - try 123 - let content = Eio.Path.load log_file in 124 - Fmt.pr "@.state file content: %s@." (String.trim content) 125 - with exn -> Fmt.pr "@.state file error: %s@." (Printexc.to_string exn)