Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions recipes/filelock-mojo/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"package": {
"name": "filelock-mojo",
"version": "0.1.0"
},
"source": {
"git": "https://github.com/henlamp/filelock-mojo.git",
"rev": "5bbf339e870cc60b35f22793472bc6f48057651f"
},
"build": {
"number": 0,
"string": "mojo110_0",
"skip": "not (osx and arm64)",
"files": [
"lib/mojo/filelock_mojo.mojoc"
],
"script": [
"mkdir -p \"$PREFIX/lib/mojo\"",
"mojo precompile --Werror src/filelock_mojo -o \"$PREFIX/lib/mojo/filelock_mojo.mojoc\""
]
},
"requirements": {
"build": [
"mojo-compiler ==1.1.0"
],
"host": [
"mojo-compiler ==1.1.0"
],
"run": [
"mojo-compiler ==1.1.0"
]
},
"tests": [
{
"script": [
"mojo run --Werror smoke.mojo"
],
"files": {
"recipe": [
"smoke.mojo"
]
}
}
],
"about": {
"homepage": "https://github.com/henlamp/filelock-mojo",
"repository": "https://github.com/henlamp/filelock-mojo.git",
"license": "MIT",
"license_file": [
"LICENSE",
"UPSTREAM_LICENSE",
"THIRD_PARTY_NOTICES.md"
],
"summary": "Unix process locks and atomic text publication in Mojo"
},
"extra": {
"maintainers": [
"henlamp"
]
}
}
32 changes: 32 additions & 0 deletions recipes/filelock-mojo/smoke.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from std.testing import assert_true
from filelock_mojo import FileLock, ReadWriteLock, LockErrorKind


def main() raises:
var owner = FileLock("installed-package.lock", timeout=0)
var rival = FileLock("installed-package.lock", timeout=0)
with owner.hold():
assert_true(owner.is_locked())
assert_true(not rival.try_acquire())
assert_true(rival.try_acquire())
rival.release()
var reader = FileLock("read.lock", timeout=0, mode=.shared)
with reader.hold():
pass
var rw = ReadWriteLock("readwrite.lock", timeout=0)
with rw.read():
pass
with rw.write():
pass
var rejected = False
try:
rw.release()
except e:
rejected = e.kind == LockErrorKind.not_held
assert_true(rejected)
var attempted = owner.try_hold()
assert_true(Bool(attempted))
with attempted.take():
assert_true(owner.lock_count() == 1)
assert_true(not owner.is_locked())
print("PASS: installed filelock_mojo")
Loading