Skip to content

Commit

Permalink
Improvements to test
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Aug 27, 2023
1 parent fcf11d1 commit 9baf08d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
21 changes: 15 additions & 6 deletions testsuite/drivers/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

import os
import os.path

import re
from shutil import copytree
from e3.os.process import Run, quote_arg

from e3.fs import mkdir
from e3.os.process import Run, quote_arg
from e3.testsuite.driver.classic import ProcessResult

import re


TESTSUITE_ROOT = os.path.dirname(os.path.dirname(
os.path.abspath(__file__)))

Expand Down Expand Up @@ -530,4 +528,15 @@ def alr_builds_dir() -> str:
"""
Return the path to the builds directory
"""
return os.path.join(alr_config_dir(), "cache", "builds")
return os.path.join(alr_config_dir(), "cache", "builds")


def external_compiler_version() -> str:
"""
Return the version of the external compiler
"""
# Obtain available compilers
p = run_alr("toolchain")

# Capture version
return re.search("gnat_external ([0-9.]+)", p.out, re.MULTILINE).group(1)
2 changes: 1 addition & 1 deletion testsuite/drivers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,4 @@ def __exit__(self, exc_type, exc_val, exc_tb):
# Release the file lock
import fcntl
fcntl.flock(self.lock_file.fileno(), fcntl.LOCK_UN)
self.lock_file.close()
self.lock_file.close()
31 changes: 25 additions & 6 deletions testsuite/tests/build/hashes/compiler-input/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import sys

from drivers.alr import run_alr, init_local_crate, alr_with
from drivers.asserts import assert_match, match_solution
from drivers.alr import external_compiler_version, run_alr, init_local_crate, alr_with
from drivers.asserts import assert_match
from drivers.builds import clear_builds_dir, hash_input


Expand All @@ -16,24 +16,43 @@ def check_hash(signature: str) -> None:
assert_match(f".*{signature}.*", hash_input("crate_real"))


run_alr("config", "--set", "--global", "dependencies.shared", "true")
# The first test is to check that the external compiler is used when no
# explicit compiler is selected.

# Select the default preferred compiler, in this index is gnat_native=8888
run_alr("toolchain", "--select")
# Disable compiler selection, so the external is used
run_alr("toolchain", "--disable-assistant")

# Enable shared dependencies
run_alr("config", "--set", "--global", "dependencies.shared", "true")

# Init a crate without explicit compiler dependency
init_local_crate("xxx")
alr_with("crate_real") # A regular crate in the index
run_alr("update") # Ensure the hash inputs are written to disk

# Check the external compiler is in the hash inputs
check_hash(f"version:gnat_external={external_compiler_version()}")


# Next, check that selecting a compiler results in it being used

# Select the default preferred compiler, in this index is gnat_native=8888
run_alr("toolchain", "--select", "gnat_native")
# Clear the build cache so we are able to locate the new hash
clear_builds_dir()
run_alr("update")
run_alr("update")
# Twice necessary because otherwise the hash inputs cannot be written (during
# the first update the destination folder does not yet exist, and the crate
# sync would remove the hash inputs file)

# Check the expected compiler is in the hash inputs
check_hash("version:gnat_native=8888.0.0")


# Next, check with an explicit compiler in the dependencies. Note that we give
# the virtual dependency, but the actual native one is used for the hash.

# Clear the build cache so we are able to locate the new hash
clear_builds_dir()
alr_with("gnat=7777") # Downgrade the compiler with an explicit dependency
run_alr("update")
Expand Down

0 comments on commit 9baf08d

Please sign in to comment.