50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
# SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
"""The Dafny pin, offline: every pinned platform has a release and a hash, an unpinned one is refused, and unpacking
|
|
keeps the executable bits Dafny and Z3 need."""
|
|
import os
|
|
import stat
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
import dafny # noqa: E402
|
|
|
|
|
|
class Pin(unittest.TestCase):
|
|
def test_every_pinned_platform_names_this_version_and_a_sha256(self):
|
|
self.assertTrue(dafny.RELEASES)
|
|
for (system, machine), (asset, digest) in dafny.RELEASES.items():
|
|
self.assertIn(dafny.VERSION, asset, f"{system} {machine}")
|
|
self.assertRegex(digest, r"^[0-9a-f]{64}$", f"{system} {machine}")
|
|
|
|
def test_the_two_platforms_pixi_pins_are_covered(self):
|
|
self.assertIn(("Linux", "x86_64"), dafny.RELEASES)
|
|
self.assertIn(("Darwin", "arm64"), dafny.RELEASES)
|
|
|
|
def test_an_unpinned_platform_is_refused_by_name(self):
|
|
with self.assertRaises(SystemExit) as e:
|
|
dafny.release("Plan9", "mips")
|
|
self.assertIn("Plan9 mips", str(e.exception))
|
|
|
|
|
|
class Unpack(unittest.TestCase):
|
|
def test_unpacking_keeps_executable_bits(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
z = Path(d) / "a.zip"
|
|
with zipfile.ZipFile(z, "w") as w:
|
|
info = zipfile.ZipInfo("dafny/dafny")
|
|
info.external_attr = (0o755 | stat.S_IFREG) << 16
|
|
w.writestr(info, "#!/bin/sh\n")
|
|
w.writestr("dafny/readme.txt", "text")
|
|
dafny.unpack(z, Path(d) / "out")
|
|
self.assertTrue(os.access(Path(d) / "out/dafny/dafny", os.X_OK))
|
|
self.assertTrue((Path(d) / "out/dafny/readme.txt").exists())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|