upstream: https://github.com/avsm/osrelease
0
fork

Configure Feed

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

fix(osrelease): fix all merlint issues (E105/E400/E405/E605)

- Fix catch-all exception → Scanf.Scan_failure | Failure (E105)
- Add module documentation comment to osrelease.mli (E400)
- Add docs for all 20 public values in Arch, OS, Distro, Version (E405)
- Create test/test_osrelease.ml/mli, test.ml, dune (E605)

+154 -1
+1 -1
lib/osrelease.ml
··· 204 204 | "macos" -> `MacOS (macos_of_string b) 205 205 | "windows" -> `Windows (windows_of_string b) 206 206 | _ -> `Other b) 207 - with _ -> `Other "" 207 + with Scanf.Scan_failure _ | Failure _ -> `Other "" 208 208 209 209 let pp fmt v = Fmt.string fmt (to_string v) 210 210
+51
lib/osrelease.mli
··· 15 15 * 16 16 *) 17 17 18 + (** OS release information: architecture, operating system, distro, and version. 19 + 20 + Detects the current system's architecture ({!Arch}), OS ({!OS}), 21 + distribution ({!Distro}), and version ({!Version}) by inspecting environment 22 + variables and running system commands such as [uname]. *) 23 + 18 24 module Arch : sig 19 25 type t = 20 26 [ `Aarch64 ··· 26 32 | `X86_64 ] 27 33 28 34 val to_string : t -> string 35 + (** [to_string arch] returns a string representation of [arch]. *) 36 + 29 37 val of_string : string -> t 38 + (** [of_string s] parses [s] into an architecture, returning [`Unknown s] if 39 + unrecognised. *) 40 + 30 41 val pp : Format.formatter -> t -> unit 42 + (** [pp ppf arch] prints [arch] on [ppf]. *) 43 + 31 44 val v : unit -> t 45 + (** [v ()] returns the architecture of the running system. *) 32 46 end 33 47 34 48 module OS : sig ··· 43 57 | `Win32 ] 44 58 45 59 val to_string : t -> string 60 + (** [to_string os] returns a string representation of [os]. *) 61 + 46 62 val of_string : string -> t 63 + (** [of_string s] parses [s] into an OS, returning [`Unknown s] if 64 + unrecognised. *) 65 + 47 66 val pp : Format.formatter -> t -> unit 67 + (** [pp ppf os] prints [os] on [ppf]. *) 68 + 48 69 val v : unit -> t 70 + (** [v ()] returns the operating system of the running system. *) 49 71 end 50 72 51 73 module Distro : sig ··· 75 97 | `Windows of windows ] 76 98 77 99 val linux_to_string : linux -> string 100 + (** [linux_to_string d] returns a string representation of the Linux distro 101 + [d]. *) 102 + 78 103 val linux_of_string : string -> linux 104 + (** [linux_of_string s] parses [s] into a Linux distro, returning [`Other s] 105 + if unrecognised. *) 106 + 79 107 val macos_to_string : macos -> string 108 + (** [macos_to_string d] returns a string representation of the macOS distro 109 + [d]. *) 110 + 80 111 val macos_of_string : string -> macos 112 + (** [macos_of_string s] parses [s] into a macOS distro. *) 113 + 81 114 val windows_to_string : windows -> string 115 + (** [windows_to_string d] returns a string representation of the Windows 116 + distro [d]. *) 117 + 82 118 val windows_of_string : string -> windows 119 + (** [windows_of_string s] parses [s] into a Windows distro. *) 120 + 83 121 val to_string : t -> string 122 + (** [to_string d] returns a string representation of the distro [d]. *) 123 + 84 124 val of_string : string -> t 125 + (** [of_string s] parses [s] into a distro, returning [`Other ""] on parse 126 + error. *) 127 + 85 128 val pp : Format.formatter -> t -> unit 129 + (** [pp ppf d] prints [d] on [ppf]. *) 130 + 86 131 val os_release_field : string -> (string option, [> `Msg of string ]) result 132 + (** [os_release_field key] reads [/etc/os-release] and returns the value of 133 + [key], or [None] if the field is absent. *) 134 + 87 135 val v : unit -> (t, [ `Msg of string ]) result 136 + (** [v ()] detects the current distribution, returning an error if detection 137 + fails. *) 88 138 end 89 139 90 140 module Version : sig 91 141 val v : unit -> (string option, [> `Msg of string ]) result 142 + (** [v ()] returns the OS version string, or [None] if not available. *) 92 143 end
+4
test/dune
··· 1 + (test 2 + (name test) 3 + (modules test test_osrelease) 4 + (libraries osrelease alcotest))
+6
test/test.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + let () = Alcotest.run "osrelease" [ Test_osrelease.suite ]
+85
test/test_osrelease.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + let test_arch_to_string () = 7 + Alcotest.(check string) "x86_64" "x86_64" (Osrelease.Arch.to_string `X86_64); 8 + Alcotest.(check string) "arm64" "arm64" (Osrelease.Arch.to_string `Aarch64); 9 + Alcotest.(check string) "x86_32" "x86_32" (Osrelease.Arch.to_string `X86_32) 10 + 11 + let test_arch_roundtrip () = 12 + List.iter 13 + (fun s -> 14 + let t = Osrelease.Arch.of_string s in 15 + Alcotest.(check string) ("roundtrip " ^ s) s (Osrelease.Arch.to_string t)) 16 + [ "x86_64"; "x86_32"; "arm64" ] 17 + 18 + let test_arch_unknown () = 19 + let s = "riscv64" in 20 + Alcotest.(check string) 21 + "unknown preserved" s 22 + (Osrelease.Arch.to_string (Osrelease.Arch.of_string s)) 23 + 24 + let test_os_to_string () = 25 + Alcotest.(check string) "linux" "linux" (Osrelease.OS.to_string `Linux); 26 + Alcotest.(check string) "macos" "macos" (Osrelease.OS.to_string `MacOS) 27 + 28 + let test_os_roundtrip () = 29 + List.iter 30 + (fun s -> 31 + let t = Osrelease.OS.of_string s in 32 + Alcotest.(check string) ("roundtrip " ^ s) s (Osrelease.OS.to_string t)) 33 + [ "linux"; "macos"; "freebsd" ] 34 + 35 + let test_distro_linux_to_string () = 36 + Alcotest.(check string) 37 + "ubuntu" "ubuntu" 38 + (Osrelease.Distro.linux_to_string `Ubuntu); 39 + Alcotest.(check string) 40 + "debian" "debian" 41 + (Osrelease.Distro.linux_to_string `Debian) 42 + 43 + let test_distro_linux_roundtrip () = 44 + List.iter 45 + (fun s -> 46 + let t = Osrelease.Distro.linux_of_string s in 47 + Alcotest.(check string) 48 + ("roundtrip " ^ s) s 49 + (Osrelease.Distro.linux_to_string t)) 50 + [ "ubuntu"; "debian"; "alpine"; "fedora" ] 51 + 52 + let test_distro_to_string () = 53 + Alcotest.(check string) 54 + "linux ubuntu" "linux ubuntu" 55 + (Osrelease.Distro.to_string (`Linux `Ubuntu)) 56 + 57 + let test_arch_v () = 58 + let _ = Osrelease.Arch.v () in 59 + () 60 + 61 + let test_os_v () = 62 + let _ = Osrelease.OS.v () in 63 + () 64 + 65 + let test_version_v () = 66 + let _ = Osrelease.Version.v () in 67 + () 68 + 69 + let suite = 70 + ( "osrelease", 71 + [ 72 + Alcotest.test_case "arch to_string" `Quick test_arch_to_string; 73 + Alcotest.test_case "arch roundtrip" `Quick test_arch_roundtrip; 74 + Alcotest.test_case "arch unknown" `Quick test_arch_unknown; 75 + Alcotest.test_case "os to_string" `Quick test_os_to_string; 76 + Alcotest.test_case "os roundtrip" `Quick test_os_roundtrip; 77 + Alcotest.test_case "distro linux to_string" `Quick 78 + test_distro_linux_to_string; 79 + Alcotest.test_case "distro linux roundtrip" `Quick 80 + test_distro_linux_roundtrip; 81 + Alcotest.test_case "distro to_string" `Quick test_distro_to_string; 82 + Alcotest.test_case "arch v" `Quick test_arch_v; 83 + Alcotest.test_case "os v" `Quick test_os_v; 84 + Alcotest.test_case "version v" `Quick test_version_v; 85 + ] )
+7
test/test_osrelease.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + val suite : string * unit Alcotest.test_case list 7 + (** [suite] is the Alcotest test suite for {!Osrelease}. *)