Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Mar 15, 2024
1 parent ab9d65c commit 48d99ef
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ commit = "9a9c660f9c6f27f5ef75417e7fac7061dff14d78"

[pins.ncdu]
url = "https://github.com/mosteo/ncdu-ada.git"
commit = "d444b5f48d5cfe89079bc507a2320eb898cf6bfa"
commit = "89f6deec1815b8b27ea906aeb51b323336122868"

[pins.semantic_versioning]
url = "https://github.com/alire-project/semantic_versioning"
Expand Down
7 changes: 5 additions & 2 deletions src/alire/alire-cache.adb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ package body Alire.Cache is
end Usage_Wrap;

begin
-- The root node should be the cache dir itself
if Tree.Length not in 1 then
-- The root node should be the cache dir itself, unless there is still
-- no cache at all.
if Tree.Is_Empty then
return Item_Sets.Empty_Set;
elsif Tree.Length not in 1 then
raise Program_Error
with "Cache tree root length /= 1:" & Tree.Length'Image;
end if;
Expand Down
5 changes: 4 additions & 1 deletion src/alr/alr-commands-cache.adb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package body Alr.Commands.Cache is
procedure Summary is
use Alire.Directories;
Table : Alire.Utils.Tables.Table;
Usage : constant Alire.Cache.Usages := Alire.Cache.Usage;
begin
Table
.Append ("Path:")
Expand All @@ -19,7 +20,9 @@ package body Alr.Commands.Cache is

Table
.Append ("Size:")
.Append (TTY_Image (Alire.Cache.Usage.First_Element.Size));
.Append (TTY_Image (if Usage.Is_Empty
then 0
else Alire.Cache.Usage.First_Element.Size));

Table.Print (Trace.Always);
end Summary;
Expand Down
37 changes: 37 additions & 0 deletions testsuite/tests/cache/summary/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Check the basic report of cache use
"""

from drivers import builds
from drivers.alr import run_alr, init_local_crate, alr_with
from drivers.asserts import assert_match

# Default cache status after clean install

assert_match("""\
Path:.*alr-config/cache
Size: 0.0 B
""",
run_alr("cache").out)

# Compile something with a dependency and there should be something in the
# cache when builds are shared.

init_local_crate()
alr_with("libhello")
run_alr("build")
p = run_alr("cache")
if builds.are_shared():
# Something already in the cache
assert_match(r"Path:.*alr-config/cache\nSize: (?!0.0 B).*\n", p.out)
else:
# Still nothing if no shared cache
assert_match(r"Path:.*alr-config/cache\nSize: 0.0 B\n", p.out)

# After installing some toolchain, for sure there should be something in the cache

run_alr("toolchain", "--select", "gnat_native=1", "gprbuild")
p = run_alr("cache")
assert_match(r"Path:.*alr-config/cache\nSize: (?!0.0 B).*\n", p.out)

print("SUCCESS")
5 changes: 5 additions & 0 deletions testsuite/tests/cache/summary/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: python-script
build_mode: both
indexes:
gnat_toolchain_index: {}
basic_index: {}

0 comments on commit 48d99ef

Please sign in to comment.