libs/html-threaded/test.lua
1#!/usr/bin/env luajit
2-- Test script for html_gen library
3
4package.path = package.path .. ";./lua/?.lua"
5
6local htmlgen = require("html_gen")
7
8print("HTML Generator Library Test")
9print("============================")
10
11-- Issue 8-059: route this test's output through the project's tmpfs-backed
12-- tmp/ symlink. DIR resolves from arg[1] or the hard-coded project path.
13local DIR = (arg and arg[1]) or "/mnt/mtwo/programming/ai-stuff/neocities-modernization"
14os.execute(string.format('"%s/scripts/ensure-tmp-symlink" "%s"', DIR, DIR))
15local TEST_DIR = DIR .. "/tmp/htmlgen-test"
16
17-- Create test directory
18os.execute("mkdir -p " .. TEST_DIR)
19
20-- Initialize with 4 threads
21print("\n1. Initializing with 4 threads...")
22local ctx = htmlgen.init(4)
23print(" Context created successfully")
24
25-- Add test files
26print("\n2. Adding test files...")
27local num_files = 100
28for i = 1, num_files do
29 local content = string.format([[<!DOCTYPE html>
30<html>
31<head><title>Test Page %d</title></head>
32<body>
33<h1>Test Page %d</h1>
34<p>This is test content for page %d.</p>
35<p>Generated by htmlgen library.</p>
36</body>
37</html>]], i, i, i)
38
39 htmlgen.add_file(ctx, string.format("%s/page-%04d.html", TEST_DIR, i), content)
40end
41print(string.format(" Added %d files to queue", num_files))
42
43-- Write all files
44print("\n3. Writing files in parallel...")
45htmlgen.write_all(ctx)
46print(" Write completed")
47
48-- Get statistics
49print("\n4. Statistics:")
50local stats = htmlgen.get_stats(ctx)
51print(string.format(" Total files: %d", stats.total_files))
52print(string.format(" Files written: %d", stats.files_written))
53print(string.format(" Files failed: %d", stats.files_failed))
54print(string.format(" Total bytes: %d", stats.total_bytes))
55print(string.format(" Elapsed time: %.3f seconds", stats.elapsed_seconds))
56print(string.format(" Throughput: %.1f files/sec", stats.files_written / stats.elapsed_seconds))
57
58-- Cleanup
59print("\n5. Cleaning up...")
60htmlgen.destroy(ctx)
61
62-- Verify files exist
63print("\n6. Verifying output...")
64local count = 0
65for i = 1, num_files do
66 local f = io.open(string.format("%s/page-%04d.html", TEST_DIR, i), "r")
67 if f then
68 count = count + 1
69 f:close()
70 end
71end
72print(string.format(" Found %d/%d files", count, num_files))
73
74-- Cleanup test files
75os.execute("rm -rf " .. TEST_DIR)
76
77if count == num_files and stats.files_failed == 0 then
78 print("\n✓ All tests passed!")
79else
80 print("\n✗ Some tests failed!")
81 os.exit(1)
82end
83