aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoronefang2026-02-05 04:04:42 +1000
committeronefang2026-02-05 04:04:42 +1000
commitaeed6be4f26e888eb42a34e16a156b1c84a8ac1d (patch)
treee34c675818aaef531646a279869658f25982625d
parentThe actual script. (diff)
downloadpolygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.zip
polygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.tar.gz
polygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.tar.bz2
polygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.tar.xz
Add test script.
-rwxr-xr-xpolygLua_test.lua181
1 files changed, 181 insertions, 0 deletions
diff --git a/polygLua_test.lua b/polygLua_test.lua
new file mode 100755
index 0000000..a26a7ff
--- /dev/null
+++ b/polygLua_test.lua
@@ -0,0 +1,181 @@
1#!/usr/bin/env luajit
2
3--- Test script for polygLua. Test 'em all!
4-- @script polygLua_test
5
6if type(jit) == 'table' then
7 print(arg[0] .. ' is being run by ' .. jit.version .. ' under ' .. jit.os .. ' on a ' .. jit.arch .. '. Lua version ' .. _VERSION)
8else
9 print(arg[0] .. ' is being run by Lua version ' .. _VERSION)
10end
11
12
13local _ = require 'polygLua'
14
15
16C'Starting from the top.'
17E'Starting from the top.'
18W'Starting from the top.'
19T'Starting from the top.'
20I'Starting from the top.'
21D'Starting from the top.'
22
23Help = [[
24This is part of the blah blah blah...
25]]
26
27Version = '0.0 crap'
28
29-- our options
30local options =
31{
32 [''] = {help = 'No actual command, do the default thing.',
33 func = function(self, options, a, args, i)
34 I'Printing options table - '
35 P(_.table2string(options, 'options'))
36 end
37 },
38 start = {help = 'Command to start the service, for Sys V init.', value = 'blah'},
39-- restart = {start},
40-- ['force-reload'] = {start},
41 status = {help = 'Command to check the status of the service, for Sys V init.',},
42 stop = {help = 'Command to stop the service, for Sys V init.',},
43 install =
44 {
45 help = 'Command to install polygLua.lua',
46 func = function(self, options, a, args, i)
47 local w = _.who
48 local d = _.pwd
49 if 'root' ~= w then
50 E'Need to be root user to install.'
51 else
52 P('not INSTALLING!!!')
53--[=[
54 P('INSTALLING!!!')
55 __[[
56#!/bin/bash
57 echo "Installing polygLua"
58 ./polygLua.lua -vvvv
59 ]]:log():show():Do()
60]=]
61 end
62 os.exit(0)
63 end
64 },
65}
66options['restart'] = options.start
67options['force-reload'] = options.start
68
69P(_.table2string(arg, 'arg'))
70P('start = ' .. options.start.value)
71_.parse(arg, options, 'polygLua_test')
72P('start = ' .. options.start.value)
73--P('stop = ' .. options.stop.value)
74
75C'After parse.'
76E'After parse.'
77W'After parse.'
78T'After parse.'
79I'After parse.'
80D'After parse.'
81
82
83__[[
84 echo -n "This'll print forking later. "
85 date
86 sleep 2
87]]:log():show():fork('echo -n "later is "; date')
88P('')
89P('')
90
91
92local GUI = 'qjackctl'
93if _.runnable'catia' then GUI = 'catia' end
94P('' .. GUI)
95P''
96
97for i,l in ipairs(__'uname -a\nfree -h':log():Do().lines) do
98 P(l)
99end
100__'uname -a':log():Then'free -h':show():Do()
101__{'uname -a', 'free -h'}:log():show():Do()
102P''
103
104
105P(__[[
106#!/bin/NoSuchCommand
107 echo "Should not print."
108]]:log():show():Do().status)
109
110P(__[[
111#!/usr/bin/env bash
112 echo "G'day world from bash."
113 exit 42
114]]:log():show():Do().status)
115
116P(__[[
117#!/usr/bin/env tcc -run
118 #include <tcclib.h>
119
120 int main()
121 {
122 printf("G'day world from C.\n");
123 exit(42);
124 }
125]]:log():show():Do().status)
126
127P(__[[
128#!/usr/bin/env tcc -run
129 #include <tcclib.h>
130
131 int main()
132 {
133 printf("G'day world from C.\n");
134 return 42;
135 }
136]]:log():show():Do().status)
137
138P(__[[
139#!/usr/bin/env luajit
140 print("G'day " .. "world " .. [=[from]=] .. ' Lua.')
141 os.exit(42)
142]]:log():show():Do().status)
143
144__[[
145#!/usr/bin/env perl
146 print "G'day world from perl.\n";
147]]:log():show():Do()
148
149__[[
150#!/usr/bin/env php
151<?php
152 print("G'day world from php.\n");
153]]:log():show():Do()
154
155-- Note no indent for Python, coz whitespace is significant.
156__[[
157#!/usr/bin/env python3
158print("G'day world from python.")
159]]:log():show():Do()
160
161__[[#!/usr/bin/env ruby
162 puts "G'day world from ruby."
163]]:log():show():Do()
164P''
165
166
167P(__'true':log():show():Do().status)
168P(__'false':log():show():Do().status)
169P(__'exit 42':log():show():Do().status)
170P(__'return 42':log():show():Do().status)
171P(__'command NoSuchCommand':log():show():Do().status)
172P''
173
174
175--__'qpdfview':forkOnce()
176--__'qpdfview':forkOnce()
177
178
179__'date':log():show():Do()
180-- Should get that "later" thing printed while the sleep is happening.
181__'date; sleep 5; date':log():show():Do()