// The pinned Dafny (scripts/dafny.py): its offline tests, and, when it has been fetched, that it is the pinned // version and verifies a program. import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { spawnSync } from 'node:child_process'; const py = spawnSync('python3', ['--version']); const ROOT = new URL('..', import.meta.url).pathname; test('the Dafny pin\'s own tests pass (python3)', { skip: py.status !== 0 ? 'python3 is not installed' : false }, () => { const r = spawnSync('python3', ['-m', 'unittest', 'discover', '-s', 'scripts/tests'], { encoding: 'utf8', cwd: ROOT }); assert.equal(r.status, 0, r.stderr); }); const exe = ROOT + '.tools/dafny-4.11.0/dafny/dafny'; test('the fetched Dafny is the pinned one, and verifies a program', { skip: fs.existsSync(exe) ? false : 'Dafny has not been fetched (pixi run dafny-fetch)' }, () => { const v = spawnSync(exe, ['--version'], { encoding: 'utf8' }); assert.match(v.stdout, /^4\.11\.0\+/); const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pplus-dafny-')); fs.writeFileSync(dir + '/max.dfy', 'method Max(a: int, b: int) returns (m: int) ensures m >= a && m >= b { if a > b { m := a; } else { m := b; } }\n'); const r = spawnSync(exe, ['verify', dir + '/max.dfy'], { encoding: 'utf8' }); fs.rmSync(dir, { recursive: true, force: true }); assert.equal(r.status, 0, r.stdout + r.stderr); assert.match(r.stdout, /1 verified, 0 errors/); });