diff options
| author | onefang | 2026-02-05 04:04:42 +1000 |
|---|---|---|
| committer | onefang | 2026-02-05 04:04:42 +1000 |
| commit | aeed6be4f26e888eb42a34e16a156b1c84a8ac1d (patch) | |
| tree | e34c675818aaef531646a279869658f25982625d | |
| parent | The actual script. (diff) | |
| download | polygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.zip polygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.tar.gz polygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.tar.bz2 polygLua-aeed6be4f26e888eb42a34e16a156b1c84a8ac1d.tar.xz | |
Add test script.
| -rwxr-xr-x | polygLua_test.lua | 181 |
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 | |||
| 6 | if type(jit) == 'table' then | ||
| 7 | print(arg[0] .. ' is being run by ' .. jit.version .. ' under ' .. jit.os .. ' on a ' .. jit.arch .. '. Lua version ' .. _VERSION) | ||
| 8 | else | ||
| 9 | print(arg[0] .. ' is being run by Lua version ' .. _VERSION) | ||
| 10 | end | ||
| 11 | |||
| 12 | |||
| 13 | local _ = require 'polygLua' | ||
| 14 | |||
| 15 | |||
| 16 | C'Starting from the top.' | ||
| 17 | E'Starting from the top.' | ||
| 18 | W'Starting from the top.' | ||
| 19 | T'Starting from the top.' | ||
| 20 | I'Starting from the top.' | ||
| 21 | D'Starting from the top.' | ||
| 22 | |||
| 23 | Help = [[ | ||
| 24 | This is part of the blah blah blah... | ||
| 25 | ]] | ||
| 26 | |||
| 27 | Version = '0.0 crap' | ||
| 28 | |||
| 29 | -- our options | ||
| 30 | local 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 | } | ||
| 66 | options['restart'] = options.start | ||
| 67 | options['force-reload'] = options.start | ||
| 68 | |||
| 69 | P(_.table2string(arg, 'arg')) | ||
| 70 | P('start = ' .. options.start.value) | ||
| 71 | _.parse(arg, options, 'polygLua_test') | ||
| 72 | P('start = ' .. options.start.value) | ||
| 73 | --P('stop = ' .. options.stop.value) | ||
| 74 | |||
| 75 | C'After parse.' | ||
| 76 | E'After parse.' | ||
| 77 | W'After parse.' | ||
| 78 | T'After parse.' | ||
| 79 | I'After parse.' | ||
| 80 | D'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') | ||
| 88 | P('') | ||
| 89 | P('') | ||
| 90 | |||
| 91 | |||
| 92 | local GUI = 'qjackctl' | ||
| 93 | if _.runnable'catia' then GUI = 'catia' end | ||
| 94 | P('' .. GUI) | ||
| 95 | P'' | ||
| 96 | |||
| 97 | for i,l in ipairs(__'uname -a\nfree -h':log():Do().lines) do | ||
| 98 | P(l) | ||
| 99 | end | ||
| 100 | __'uname -a':log():Then'free -h':show():Do() | ||
| 101 | __{'uname -a', 'free -h'}:log():show():Do() | ||
| 102 | P'' | ||
| 103 | |||
| 104 | |||
| 105 | P(__[[ | ||
| 106 | #!/bin/NoSuchCommand | ||
| 107 | echo "Should not print." | ||
| 108 | ]]:log():show():Do().status) | ||
| 109 | |||
| 110 | P(__[[ | ||
| 111 | #!/usr/bin/env bash | ||
| 112 | echo "G'day world from bash." | ||
| 113 | exit 42 | ||
| 114 | ]]:log():show():Do().status) | ||
| 115 | |||
| 116 | P(__[[ | ||
| 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 | |||
| 127 | P(__[[ | ||
| 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 | |||
| 138 | P(__[[ | ||
| 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 | ||
| 158 | print("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() | ||
| 164 | P'' | ||
| 165 | |||
| 166 | |||
| 167 | P(__'true':log():show():Do().status) | ||
| 168 | P(__'false':log():show():Do().status) | ||
| 169 | P(__'exit 42':log():show():Do().status) | ||
| 170 | P(__'return 42':log():show():Do().status) | ||
| 171 | P(__'command NoSuchCommand':log():show():Do().status) | ||
| 172 | P'' | ||
| 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() | ||
