diff --git a/alire.toml b/alire.toml index 87206b413..107a13cfd 100644 --- a/alire.toml +++ b/alire.toml @@ -15,7 +15,7 @@ project-files = ["alr.gpr"] executables = ["alr"] [[depends-on]] -aaa = "~0.2.7" +aaa = "~0.3.0" ada_toml = "~0.3" ajunitgen = "^1.0.1" ansiada = "^1.0" @@ -45,9 +45,9 @@ windows = { ALIRE_OS = "windows" } # Some dependencies require precise versions during the development cycle: [[pins]] -aaa = { url = "https://github.com/mosteo/aaa", commit = "f60254934a7d6e39b72380b496527295602f75e3" } +aaa = { url = "https://github.com/mosteo/aaa", commit = "fbfffb1cb269a852201d172119d94f3024b617f2" } ada_toml = { url = "https://github.com/mosteo/ada-toml", commit = "da4e59c382ceb0de6733d571ecbab7ea4919b33d" } -clic = { url = "https://github.com/alire-project/clic", commit = "8d26222de71014554999e48c821906fca0e3dc41" } +clic = { url = "https://github.com/alire-project/clic", commit = "6879b90876a1c918b4e112f59c6db0e25b713f52" } gnatcoll = { url = "https://github.com/alire-project/gnatcoll-core.git", commit = "403efe11405113cf12ae3d014df474cf7a046176" } minirest = { url = "https://github.com/mosteo/minirest.git", commit = "17fa789b71ccaf65e8c892816456c94a09a384d0" } semantic_versioning = { url = "https://github.com/alire-project/semantic_versioning", commit = "2f23fc5f6b4855b836b599adf292fed9c0ed4144" } diff --git a/deps/clic b/deps/clic index 8d26222de..6879b9087 160000 --- a/deps/clic +++ b/deps/clic @@ -1 +1 @@ -Subproject commit 8d26222de71014554999e48c821906fca0e3dc41 +Subproject commit 6879b90876a1c918b4e112f59c6db0e25b713f52 diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-config-edit.adb index 7967b37f8..9f50e3a90 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-config-edit.adb @@ -67,6 +67,25 @@ package body Alire.Config.Edit is end case; end Set; + ----------- + -- Unset -- + ----------- + + procedure Unset (Level : Config.Level; + Key : CLIC.Config.Config_Key) + is + begin + if CLIC.Config.Edit.Unset (Filepath (Level), Key, Quiet => True) then + Trace.Debug ("Config key " & Key & " unset from " & Level'Image + & "configuration at " & Filepath (Level)); + Load_Config; + else + Trace.Debug ("Config key " & Key & " requested to be unset at level " + & Level'Image & " but it was already unset at " + & Filepath (Level)); + end if; + end Unset; + ----------------- -- Set_Boolean -- ----------------- diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index a34aa12ed..011bb873c 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -36,6 +36,10 @@ package Alire.Config.Edit is -- here all non-preelaborable things related to config loading. This -- way, querying stays preelaborable. + procedure Unset (Level : Config.Level; + Key : CLIC.Config.Config_Key); + -- Unset a key at a level; silently succeed even if the key was undefined. + function Path return Absolute_Path; -- The in-use global config folder path. -- In order of decreasing precedence: diff --git a/src/alire/alire-origins-deployers-system-macports.adb b/src/alire/alire-origins-deployers-system-macports.adb new file mode 100644 index 000000000..8fac68eb6 --- /dev/null +++ b/src/alire/alire-origins-deployers-system-macports.adb @@ -0,0 +1,114 @@ +with AAA.Strings; use AAA.Strings; + +with Alire.OS_Lib.Subprocess; +with Alire.Errors; + +package body Alire.Origins.Deployers.System.Macports is + + -- Ada.Strings.Unbounded is use-visible via Alire.Origins. + + package Subprocess renames Alire.OS_Lib.Subprocess; + + ----------------------- + -- Already_Installed -- + ----------------------- + + overriding function Already_Installed (This : Deployer) return Boolean + is + Installed : AAA.Strings.Vector; + begin + Trace.Debug ("already_installed? " & This.Base.Package_Name); + + if Subprocess.Unchecked_Spawn_And_Capture + ("port", + Empty_Vector & "echo" & "installed", + Output => Installed, + Err_To_Out => True) /= 0 + then + -- failed. + Trace.Debug ("port failed to find any installed packages"); + return False; + end if; + + -- We get a list of all the installed packages, + -- name {spaces} '@' version + + Trace.Debug (Installed.Length'Image & " installed packages"); + + for P of Installed loop + Trace.Debug ("Checking '" & P & "'"); + if AAA.Strings.Head (P, ' ') = This.Base.Package_Name then + Trace.Debug ("found '" & P & "'"); + return True; + end if; + end loop; + + return False; -- until we've implemented Install + end Already_Installed; + + ------------ + -- Detect -- + ------------ + + -- Returns the package version, if the package exists, whether or + -- not it's installed. + -- + -- If it's not installed, what you get is the version that would + -- be installed. + + overriding + function Detect (This : Deployer) return Version_Outcomes.Outcome + is + Info : AAA.Strings.Vector; + begin + Trace.Debug ("detect? " & This.Base.Package_Name); + + if Subprocess.Unchecked_Spawn_And_Capture + ("port", + Empty_Vector & "info" & "--version" & This.Base.Package_Name, + Output => Info, + Err_To_Out => True) /= 0 + then + -- failed. + Trace.Debug ("port failed to find " & This.Base.Package_Name); + return Version_Outcomes.Outcome_Failure + ("no candidate version found", + Report => False); + end if; + + if Integer (Info.Length) /= 1 then + raise Constraint_Error + with "port info --version returned" & Info.Length'Image & " lines."; + end if; + + Trace.Debug ("port info output: " & Info (Info.First)); + declare + Version : constant String := Trim (Tail (Info (Info.First), ':')); + begin + Trace.Debug (" -> version: '" & Version & "'"); + return Version_Outcomes.New_Result (Semantic_Versioning.Parse + (Version, + Relaxed => True)); + end; + + end Detect; + + ------------- + -- Install -- + ------------- + + overriding + function Install (This : Deployer) return Outcome is + begin + Trace.Debug ("hoping to install: " & This.Base.Image); + Subprocess.Checked_Spawn + ("sudo", + Empty_Vector & "port" & "install" & This.Base.Package_Name); + + return Outcome_Success; + exception + when E : others => + return Alire.Errors.Get (E); + end Install; + +end Alire.Origins.Deployers.System.Macports; diff --git a/src/alire/alire-origins-deployers-system-macports.ads b/src/alire/alire-origins-deployers-system-macports.ads new file mode 100644 index 000000000..7c7fc92d3 --- /dev/null +++ b/src/alire/alire-origins-deployers-system-macports.ads @@ -0,0 +1,15 @@ +package Alire.Origins.Deployers.System.Macports is + + type Deployer is new Deployers.System.Deployer with null record; + + overriding + function Already_Installed (This : Deployer) return Boolean; + + overriding + function Detect (This : Deployer) + return Version_Outcomes.Outcome; + + overriding + function Install (This : Deployer) return Outcome; + +end Alire.Origins.Deployers.System.Macports; diff --git a/src/alire/alire-origins-deployers-system.adb b/src/alire/alire-origins-deployers-system.adb index c094c7aa7..efecf97c8 100644 --- a/src/alire/alire-origins-deployers-system.adb +++ b/src/alire/alire-origins-deployers-system.adb @@ -1,5 +1,6 @@ with Alire.Origins.Deployers.System.Apt; with Alire.Origins.Deployers.System.Homebrew; +with Alire.Origins.Deployers.System.Macports; with Alire.Origins.Deployers.System.Pacman; with Alire.Origins.Deployers.System.RPM_Wrappers; with Alire.Origins.Deployers.System.Zypper; @@ -108,6 +109,9 @@ package body Alire.Origins.Deployers.System is with others => <>), when Platforms.Homebrew => System.Homebrew.Deployer'(Deployers.Deployer'(Base => From) + with others => <>), + when Platforms.Macports => + System.Macports.Deployer'(Deployers.Deployer'(Base => From) with others => <>)); -- NOTE: add here other native package managers as they get -- implemented. diff --git a/src/alire/alire-origins.ads b/src/alire/alire-origins.ads index 450021c12..233fbf83b 100644 --- a/src/alire/alire-origins.ads +++ b/src/alire/alire-origins.ads @@ -37,9 +37,16 @@ package Alire.Origins is subtype Archive_Kinds is Kinds with Static_Predicate => Archive_Kinds in Binary_Archive | Source_Archive; + subtype Deployable_Kinds is Kinds + with Static_Predicate => Deployable_Kinds not in External; + -- Origins that require deployment + subtype External_Kinds is Kinds with Static_Predicate => External_Kinds in External | System; + subtype Source_Kinds is Kinds range Filesystem .. Source_Archive; + -- These are kinds that have actual sources that are deployed and built + subtype VCS_Kinds is Kinds range Git .. SVN; type Source_Archive_Format is (Unknown, Tarball, Zip_Archive); @@ -100,10 +107,11 @@ package Alire.Origins is function Package_Name (This : Origin) return String with Pre => This.Kind = System; - function Is_Regular (This : Origin) return Boolean is + function Is_Index_Provided (This : Origin) return Boolean is (This.Kind not in External | System); - -- A regular origin is one that is compiled from sources, instead of coming - -- from external definitions (detected or not). + -- One that is deployed via built sources or fetched binaries pointed to by + -- an index, instead of coming from locally detected executables or system + -- packages. function Short_Unique_Id (This : Origin) return String with Pre => This.Kind in Git | Hg | Archive_Kinds; diff --git a/src/alire/alire-platforms.ads b/src/alire/alire-platforms.ads index 4903f98a6..13507132a 100644 --- a/src/alire/alire-platforms.ads +++ b/src/alire/alire-platforms.ads @@ -42,6 +42,7 @@ package Alire.Platforms with Preelaborate is Fedora, Suse, Homebrew, + Macports, Distro_Unknown); subtype Known_Distributions is @@ -58,6 +59,7 @@ package Alire.Platforms with Preelaborate is Dnf, Zypper, Homebrew, + Macports, Packager_Unknown); Distro_Manager : constant array (Distributions) of Package_Managers := @@ -67,6 +69,7 @@ package Alire.Platforms with Preelaborate is Centos | Fedora => Dnf, Suse => Zypper, Homebrew => Homebrew, + Macports => Macports, Distro_Unknown => Packager_Unknown); type Toolchains is (System, diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 25cef86f3..0a0bdebb9 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -56,9 +56,9 @@ package body Alire.Roots is -- Relocate to the release folder CD : Directories.Guard - (if State.Has_Release and then State.Release.Origin.Is_Regular - then Directories.Enter (This.Release_Base (State.Crate)) - else Directories.Stay) with Unreferenced; + (if State.Has_Release and then State.Release.Origin.Is_Index_Provided + then Directories.Enter (This.Release_Base (State.Crate)) + else Directories.Stay) with Unreferenced; --------------------------- -- Run_Pre_Build_Actions -- @@ -696,7 +696,7 @@ package body Alire.Roots is -- Binary releases are always installed as shared releases Shared.Share (Rel); - elsif Dep.Is_Shared and then not Rel.Origin.Is_Regular then + elsif Dep.Is_Shared and then not Rel.Origin.Is_Index_Provided then -- Externals shouldn't leave a trace in the binary cache Trace.Debug ("deploy: skip shared external"); diff --git a/src/alire/alire-roots.ads b/src/alire/alire-roots.ads index ca23be140..663138c26 100644 --- a/src/alire/alire-roots.ads +++ b/src/alire/alire-roots.ads @@ -377,7 +377,7 @@ private Crate : Crate_Name) return Any_Path; -- The path at which dependencies have to be deployed, which for regular - -- releases is simply ./alire/cache/dependencies, unless overriden by the + -- releases is simply ./alire/cache/dependencies, unless overridden by the -- config option `dependencies.dir` end Alire.Roots; diff --git a/src/alire/alire-shared.adb b/src/alire/alire-shared.adb index 932d3f6e8..c8285ab39 100644 --- a/src/alire/alire-shared.adb +++ b/src/alire/alire-shared.adb @@ -78,7 +78,7 @@ package body Alire.Shared is for Release of Index.Releases_Satisfying (Toolchains.Any_Tool (Tool), Root.Platform_Properties) loop - if not Release.Origin.Is_Regular then + if not Release.Origin.Is_Index_Provided then Result.Include (Release); end if; end loop; @@ -220,7 +220,7 @@ package body Alire.Shared is Path : constant Absolute_Path := Shared.Path / Release.Deployment_Folder; begin - if not Release.Origin.Is_Regular then + if not Release.Origin.Is_Index_Provided then Raise_Checked_Error ("Only regular releases deployed through Alire can be removed."); end if; diff --git a/src/alire/alire-solutions-diffs.adb b/src/alire/alire-solutions-diffs.adb index fc2d921c8..d102b5afd 100644 --- a/src/alire/alire-solutions-diffs.adb +++ b/src/alire/alire-solutions-diffs.adb @@ -42,7 +42,7 @@ package body Alire.Solutions.Diffs is when Unpinned => TTY.Emph (U ("🎈")), -- alts: 𐩒🎈 when Unchanged => TTY.OK (U ("=")), when Missing => TTY.Error (U ("❗")), -- alts: ⚠️❗‼️ - when Shared => TTY.Emph (U ("♻️ ")), -- alts: ♻️♼ + when Shared => TTY.Emph (U ("♻️ ")), -- alts: ♻♻️♼🫴 when Binary => TTY.Warn (U ("📦"))) else (case Change is diff --git a/src/alire/alire-solver.adb b/src/alire/alire-solver.adb index 96977d180..982414550 100644 --- a/src/alire/alire-solver.adb +++ b/src/alire/alire-solver.adb @@ -1040,11 +1040,11 @@ package body Alire.Solver is else - -- The crate plainly doesn't exist in our loaded catalog, so + -- The crate plainly doesn't exist in our loaded index, so -- mark it as missing an move on: Trace.Debug - ("SOLVER: catalog LACKS the crate " & Raw_Dep.Image + ("SOLVER: index LACKS the crate " & Raw_Dep.Image & " when the search tree was " & Image_One_Line (State)); diff --git a/src/alire/alire-solver.ads b/src/alire/alire-solver.ads index 8c788bce3..238811388 100644 --- a/src/alire/alire-solver.ads +++ b/src/alire/alire-solver.ads @@ -88,7 +88,7 @@ package Alire.Solver is --------------------- -- Basic queries -- - -- Merely check the catalog + -- Merely check the index function Exists (Name : Alire.Crate_Name; Version : Semantic_Versioning.Version; @@ -123,7 +123,7 @@ package Alire.Solver is ----------------------- -- Advanced queries -- - -- They may need to travel the full catalog, with multiple individual + -- They may need to travel the full index, with multiple individual -- availability checks. type Query_Options is record diff --git a/src/alire/alire-toml_index.adb b/src/alire/alire-toml_index.adb index 87a682090..216ae6952 100644 --- a/src/alire/alire-toml_index.adb +++ b/src/alire/alire-toml_index.adb @@ -47,15 +47,16 @@ package body Alire.TOML_Index is Root : Any_Path; Result : out Load_Result) with Pre => Result.Success; - -- Check that Catalog_Dir contains a file called "index.toml" and that it - -- describes a supported catalog. + -- Check that the index contains a file called "index.toml" and that it + -- describes a supported index, and that the file tree follows the proper + -- naming conventions, without extraneous files being present. procedure Load_Manifest (Item : Ada.Directories.Directory_Entry_Type; Stop : in out Boolean); -- Check if entry is a candidate to manifest file, and in that case load -- its contents. May raise Checked_Error. - procedure Load_From_Catalog_Internal + procedure Load_From_Index_Internal (File_Name : Absolute_Path; Name : Crate_Name; Version : String; @@ -289,7 +290,7 @@ package body Alire.TOML_Index is TOML_Index.Strict := Load.Strict; - Trace.Detail ("Loading full catalog from " & Root); + Trace.Detail ("Loading full index from " & Root); Check_Index (Index, Root, Result); @@ -418,7 +419,7 @@ package body Alire.TOML_Index is & Path); end if; - Load_From_Catalog_Internal (File_Name => Path, + Load_From_Index_Internal (File_Name => Path, Name => FS_Name, Version => FS_Version, Strict => Strict); @@ -426,11 +427,11 @@ package body Alire.TOML_Index is end; end Load_Manifest; - -------------------------------- - -- Load_From_Catalog_Internal -- - -------------------------------- + ------------------------------ + -- Load_From_Index_Internal -- + ------------------------------ - procedure Load_From_Catalog_Internal + procedure Load_From_Index_Internal (File_Name : Absolute_Path; Name : Crate_Name; Version : String; @@ -511,7 +512,7 @@ package body Alire.TOML_Index is Manifest.Index, Strict)); end if; - end Load_From_Catalog_Internal; + end Load_From_Index_Internal; ------------------- -- Index_Release -- diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index e4b0f8946..99039c602 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -132,7 +132,8 @@ package body Alire.Toolchains is (Index.Releases_Satisfying (Any_Tool (Crate), Env)) loop - if Release.Origin.Is_Regular and then Is_Valid_Choice (Release) + if Release.Origin.Is_Index_Provided and then + Is_Valid_Choice (Release) then -- We want the newest native compiler packaged by Alire to @@ -189,7 +190,7 @@ package body Alire.Toolchains is -- Deploy as a shared install unless external - if Release.Origin.Is_Regular then + if Release.Origin.Is_Index_Provided then Shared.Share (Release); else Trace.Debug @@ -284,7 +285,7 @@ package body Alire.Toolchains is Pick_Up_Tool (Crate, Fill_Version_Choices (Crate)); else Put_Warning - ("No indexed versions in the catalog for crate " + ("No indexed versions found for crate " & Crate.TTY_Image); end if; @@ -400,7 +401,7 @@ package body Alire.Toolchains is Alire.Config.Edit.Set_Boolean (Level, Key => Tool_Key (Release.Name, For_Is_External), - Value => not Release.Origin.Is_Regular); + Value => not Release.Origin.Is_Index_Provided); end Set_As_Default; ----------------------------- diff --git a/src/alire/alire-toolchains.ads b/src/alire/alire-toolchains.ads index 9dc7fd29e..06d0ed712 100644 --- a/src/alire/alire-toolchains.ads +++ b/src/alire/alire-toolchains.ads @@ -99,7 +99,7 @@ package Alire.Toolchains is & "dependencies on particular compiler crates, for example to " & "use a cross-compiler. In this situation, a compiler already " & "available (selected as default or already installed) will " - & "take precedence over a compiler available in the catalog. ") + & "take precedence over a compiler available in the index. ") .Append ("") .Append ("See also " & TTY.URL ("https://alire.ada.dev/docs/#toolchains") & " for " diff --git a/src/alire/alire-utils-tools.adb b/src/alire/alire-utils-tools.adb index 6da9fd244..9d3dc4e92 100644 --- a/src/alire/alire-utils-tools.adb +++ b/src/alire/alire-utils-tools.adb @@ -57,7 +57,7 @@ package body Alire.Utils.Tools is return ""; when Msys2 | Debian | Ubuntu | Arch | Centos | Fedora | Rhel | Suse - | Homebrew => + | Homebrew | Macports => return (case Tool is when Easy_Graph => (if Distribution = Centos or else diff --git a/src/alire/os_macos/alire-platforms-current__macos.adb b/src/alire/os_macos/alire-platforms-current__macos.adb index 3e2c1cc6a..e67991366 100644 --- a/src/alire/os_macos/alire-platforms-current__macos.adb +++ b/src/alire/os_macos/alire-platforms-current__macos.adb @@ -1,31 +1,47 @@ with Alire.OS_Lib; +with GNAT.OS_Lib; package body Alire.Platforms.Current is -- macOS implementation - -- Homebrew only at this time (2022-09-13) + -- Homebrew Homebrew_Prefix : constant String := Alire.OS_Lib.Getenv ("HOMEBREW_PREFIX", ""); Homebrew_Present : constant Boolean := Homebrew_Prefix /= ""; + -- MacPorts + Port_Access : constant GNAT.OS_Lib.String_Access + := GNAT.OS_Lib.Locate_Exec_On_Path ("port"); + use type GNAT.OS_Lib.String_Access; + Macports_Present : constant Boolean := Port_Access /= null; + ------------------ -- Distribution -- ------------------ function Detected_Distribution return Platforms.Distributions is - (if Homebrew_Present - then Homebrew - else Distro_Unknown); + begin + if Homebrew_Present + then + return Homebrew; + elsif Macports_Present then + return Macports; + else + return Distro_Unknown; + end if; + end Detected_Distribution; ----------------------- -- Distribution_Root -- ----------------------- function Distribution_Root return Absolute_Path - is (if Homebrew_Present - then Homebrew_Prefix - else "/"); + is (if Homebrew_Present + then Homebrew_Prefix + elsif Macports_Present + then "/opt/local" + else "/"); ---------------------- -- Load_Environment -- diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index 7dd27bdc6..8998883eb 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -345,7 +345,7 @@ package body Alr.Commands.Get is if not Alire.Index.Exists (Allowed.Crate) then Reportaise_Command_Failed - ("Crate [" & Args (1) & "] does not exist in the catalog."); + ("Crate [" & Args (1) & "] does not exist in the index."); end if; Check_Unavailable_External (Allowed.Crate); @@ -355,7 +355,7 @@ package body Alr.Commands.Get is if not Query.Exists (Allowed.Crate, Allowed.Versions) then Reportaise_Command_Failed ("Release within the requested versions [" - & Allowed.TTY_Image & "] does not exist in the catalog."); + & Allowed.TTY_Image & "] does not exist in the index."); end if; Retrieve (Cmd, Allowed.Crate, Allowed.Versions); diff --git a/src/alr/alr-commands-toolchain.adb b/src/alr/alr-commands-toolchain.adb index 0f9b61fde..a4f36b2fe 100644 --- a/src/alr/alr-commands-toolchain.adb +++ b/src/alr/alr-commands-toolchain.adb @@ -244,7 +244,7 @@ package body Alr.Commands.Toolchain is -- And perform the actual installation if Cmd.Install_Dir.all /= "" then - if Rel.Origin.Is_Regular then + if Rel.Origin.Is_Index_Provided then Shared.Share (Rel, Cmd.Install_Dir.all); else Reportaise_Command_Failed @@ -253,7 +253,7 @@ package body Alr.Commands.Toolchain is & Rel.Milestone.TTY_Image & " is: " & Rel.Origin.Kind'Image); end if; else - if Rel.Origin.Is_Regular then + if Rel.Origin.Is_Index_Provided then Shared.Share (Rel); elsif Rel.Origin.Is_System then Origins.Deployers.Deploy (Rel).Assert; diff --git a/src/alr/alr-commands-withing.adb b/src/alr/alr-commands-withing.adb index 8660ea8b5..bce6f55f8 100644 --- a/src/alr/alr-commands-withing.adb +++ b/src/alr/alr-commands-withing.adb @@ -228,6 +228,10 @@ package body Alr.Commands.Withing is is Flags : Natural := 0; + ----------- + -- Check -- + ----------- + procedure Check (Flag : Boolean) is begin if Flag then diff --git a/src/alr/alr-commands.ads b/src/alr/alr-commands.ads index 1d9b26b77..a1f3bf5cc 100644 --- a/src/alr/alr-commands.ads +++ b/src/alr/alr-commands.ads @@ -146,4 +146,8 @@ private TTY_Underline => Alire.TTY.Underline, TTY_Emph => Alire.TTY.Emph); + Unset : constant String := "unset"; + -- Canary for text switches that can be both ungiven, given without value, + -- and given with value. + end Alr.Commands; diff --git a/testsuite/drivers/asserts.py b/testsuite/drivers/asserts.py index 5097fec40..9515d5b90 100644 --- a/testsuite/drivers/asserts.py +++ b/testsuite/drivers/asserts.py @@ -53,13 +53,17 @@ def assert_contents(dir: str, expected, regex: str = ""): def assert_match(expected_re, actual, label=None, flags=re.S): - if not re.match(expected_re, actual, flags=flags): - text = ['Unexpected {}'.format(label or 'output'), - 'Expecting a match on:', - indent(expected_re), - 'But got:', - indent(actual)] - assert False, '\n'.join(text) + try: + if not re.match(expected_re, actual, flags=flags): + text = ['Unexpected {}'.format(label or 'output'), + 'Expecting a match on:', + indent(expected_re), + 'But got:', + indent(actual)] + assert False, '\n'.join(text) + except re.error as e: + print(f"Invalid regex at assert_match: {expected_re}", file=sys.stderr) + raise def assert_profile(profile: str, crate: str, root: str = "."): @@ -112,4 +116,16 @@ def assert_in_file(path : str, expected : str): with open(path, "r") as f: contents = f.read() assert expected in contents, \ - f"Missing expected string '{expected}' in file {path}:\n{contents}" \ No newline at end of file + f"Missing expected string '{expected}' in file {path}:\n{contents}" + + +def match_deploy_dir(crate : str, path_fragment : str): + """ + Check that a deployment directory for a crate matches a regex. The path + fragment must be anything between the variable name and the crate name in + the output of printenv, e.g.: MAKE_ALIRE_PREFIX= + """ + p = run_alr("printenv") + assert_match(f".*[: ]{crate.upper()}_ALIRE_PREFIX=[^\\n]*" + f"{re.escape(path_fragment)}[^\\n]*{crate}_.*", + p.out) diff --git a/testsuite/tests/get/get-not-found/test.py b/testsuite/tests/get/get-not-found/test.py index db3b769e3..f59e890b1 100644 --- a/testsuite/tests/get/get-not-found/test.py +++ b/testsuite/tests/get/get-not-found/test.py @@ -10,7 +10,7 @@ p = run_alr('get', 'does_not_exist', complain_on_error=False) assert_eq(1, p.status) -assert_match('.*Crate \[does_not_exist\] does not exist in the catalog\.\n', +assert_match('.*Crate \[does_not_exist\] does not exist in the index\.\n', p.out) assert_eq([], glob('does_not_exist*'))