Many of our tests in `tests/lean/run/` produce output from `#eval` (or `#check`) statements, that is then ignored. This PR tries to capture all the useful output using `#guard_msgs`. I've only done a cursory check that the output is still sane --- there is a chance that some "unchecked" tests have already accumulated regressions and this just cements them! In the other direction, I did identify two rotten tests: * a minor one in `setStructInstNotation.lean`, where a comment says `Set Nat`, but `#check` actually prints `?_`. Weird? * `CompilerProbe.lean` is generating empty output, apparently indicating that something is broken, but I don't know the signficance of this file. In any case, I'll ask about these elsewhere. (This started by noticing that a recent `grind` test file had an untested `trace_state`, and then got carried away.)
52 lines
1.5 KiB
Text
52 lines
1.5 KiB
Text
/-!
|
|
This test covers the file handle locking functionality in `IO`.
|
|
-/
|
|
|
|
def testFile := "handleLocking.lock"
|
|
|
|
/-- Test an exclusive lock. -/
|
|
def test1 : IO Unit := do
|
|
let h1 ← IO.FS.Handle.mk testFile .write
|
|
h1.lock
|
|
let h2 ← IO.FS.Handle.mk testFile .write
|
|
if (← h2.tryLock) then
|
|
throw <| IO.userError "incorrectly acquired 2 exclusive locks"
|
|
if (← h2.tryLock (exclusive := false)) then
|
|
throw <| IO.userError "incorrectly acquired an exclusive and shared lock"
|
|
h1.unlock
|
|
unless (← h2.tryLock) do
|
|
throw <| IO.userError "failed to unlock exclusive lock and then lock"
|
|
|
|
/-- info: -/
|
|
#guard_msgs in
|
|
#eval test1
|
|
|
|
/-- Test unlock on handle free (and thus a close). -/
|
|
def test2 : IO Unit := do
|
|
let h ← IO.FS.Handle.mk testFile .write
|
|
h.lock
|
|
let h ← IO.FS.Handle.mk testFile .write -- expected to free old `h`
|
|
unless (← h.tryLock) do
|
|
throw <| IO.userError "handle free failed to unlock"
|
|
|
|
/-- info: -/
|
|
#guard_msgs in
|
|
#eval test2
|
|
|
|
/-- Test shared locks. -/
|
|
def test3 : IO Unit := do
|
|
let h1 ← IO.FS.Handle.mk testFile .write
|
|
h1.lock (exclusive := false)
|
|
let h2 ← IO.FS.Handle.mk testFile .write
|
|
if (← h2.tryLock) then
|
|
throw <| IO.userError "incorrectly acquired a shared and exclusive lock"
|
|
unless (← h2.tryLock (exclusive := false)) do
|
|
throw <| IO.userError "failed to acquire 2 shared locks"
|
|
h1.unlock
|
|
h2.unlock
|
|
unless (← h2.tryLock) do
|
|
throw <| IO.userError "failed to unlock shared locks and then lock"
|
|
|
|
/-- info: -/
|
|
#guard_msgs in
|
|
#eval test3
|