From 437af69acb7625603c4a3255c9cd1728c5807c61 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Sat, 23 May 2020 20:52:36 +0200 Subject: [PATCH] Fix missing checks for invalid solution (#420) * Fix missing checks for invalid solution These were causing uncontained errors after an `alr get --only` * Test for proper behavior after `alr get --only` --- src/alire/alire-solutions.adb | 15 ++++++++++- src/alire/alire-solutions.ads | 5 +++- src/alr/alr-commands-get.adb | 5 ---- testsuite/tests/get/only/test.py | 40 ++++++++++++++++++++++++++++++ testsuite/tests/get/only/test.yaml | 3 +++ 5 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 testsuite/tests/get/only/test.py create mode 100644 testsuite/tests/get/only/test.yaml diff --git a/src/alire/alire-solutions.adb b/src/alire/alire-solutions.adb index e122e625..805082a4 100644 --- a/src/alire/alire-solutions.adb +++ b/src/alire/alire-solutions.adb @@ -98,6 +98,17 @@ package body Alire.Solutions is Detailed : Boolean; Level : Trace.Levels) is begin + + -- For invalid solutions be terse and gone + + if not This.Valid then + Trace.Log ("Dependencies (solution):", Level); + Trace.Log (" No solution", Level); + return; + end if; + + -- Continue for valid solutions + if not This.Releases.Is_Empty then Trace.Log ("Dependencies (solution):", Level); for Rel of This.Releases loop @@ -167,7 +178,9 @@ package body Alire.Solutions is procedure Print_Pins (This : Solution) is Table : Utils.Tables.Table; begin - if not (for some Release of This.Releases => Release.Is_Pinned) then + if not This.Valid then + Trace.Always ("There is no solution, hence there are no pins"); + elsif not (for some Release of This.Releases => Release.Is_Pinned) then Trace.Always ("There are no pins"); else for Release of This.Releases loop diff --git a/src/alire/alire-solutions.ads b/src/alire/alire-solutions.ads index b17268d3..02328b48 100644 --- a/src/alire/alire-solutions.ads +++ b/src/alire/alire-solutions.ads @@ -50,7 +50,10 @@ package Alire.Solutions is function Changing_Pin (This : Solution; Name : Crate_Name; - Pinned : Boolean) return Solution; + Pinned : Boolean) return Solution + with Pre => + This.Valid or else + raise Checked_Error with "Cannot change pins in invalid solution"; -- Return a copy of the solution with the new pinning status of Name function Pins (This : Solution) return Conditional.Dependencies; diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index 3f382e25..f362c282 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -162,11 +162,6 @@ package body Alr.Commands.Get is else Trace.Info ("There are no dependencies."); end if; - - exception - when Alire.Query_Unsuccessful => - Trace.Info ("Release [" & Query.Dependency_Image (Name, Versions) & - "] does not exist in the catalog."); end Retrieve; ------------- diff --git a/testsuite/tests/get/only/test.py b/testsuite/tests/get/only/test.py new file mode 100644 index 00000000..81f45d3b --- /dev/null +++ b/testsuite/tests/get/only/test.py @@ -0,0 +1,40 @@ +""" +Test proper working of alr get --only and other follow-up commands in such an +invalid solution state +""" + +from glob import glob +import os +import re + +from drivers.alr import run_alr +from drivers.asserts import assert_eq, assert_match + + +# Get the "hello" project and enter its directory, without solving dependencies +run_alr('get', 'hello', '--only') +os.chdir(glob('hello*')[0]) + +# Verify that it has no solution +p = run_alr('with', '--solve') +assert_eq('Dependencies (direct):\n' + ' libhello^1.0\n' + 'Dependencies (solution):\n' + ' No solution\n', + p.out) + +# Verify that it has no pins +p = run_alr('pin') +assert_eq('There is no solution, hence there are no pins\n', p.out) + +# Verify that updating it fixes the solution +run_alr('update') +p = run_alr('with', '--solve') +assert_match('.*\n' # Skip dependencies + 'Dependencies \(solution\):\n' + ' libhello=1\.0\.0.*\n' + '.*', # Skip graph + p.out, flags=re.S) + + +print('SUCCESS') diff --git a/testsuite/tests/get/only/test.yaml b/testsuite/tests/get/only/test.yaml new file mode 100644 index 00000000..872fc127 --- /dev/null +++ b/testsuite/tests/get/only/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + basic_index: {} -- 2.39.5