aboutsummaryrefslogtreecommitdiffstats
path: root/polygLua_test.lua
blob: a26a7ffc67b8463dec1c06933fc3702aa8636650 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env luajit

--- Test script for polygLua. Test 'em all!
-- @script polygLua_test

if type(jit) == 'table' then
  print(arg[0] .. ' is being run by ' .. jit.version .. ' under ' .. jit.os .. ' on a ' .. jit.arch .. '.  Lua version ' .. _VERSION)
else
  print(arg[0] .. ' is being run by Lua version ' .. _VERSION)
end


local _ = require 'polygLua'


C'Starting from the top.'
E'Starting from the top.'
W'Starting from the top.'
T'Starting from the top.'
I'Starting from the top.'
D'Starting from the top.'

Help = [[
This is part of the blah blah blah...
]]

Version = '0.0 crap'

-- our options
local options =
{
    [''] =	{help = 'No actual command, do the default thing.',
	func = function(self, options, a, args, i)
	    I'Printing options table - '
	    P(_.table2string(options, 'options'))
	end
    },
    start =	{help = 'Command to start the service, for Sys V init.', value = 'blah'},
--    restart = {start},
--    ['force-reload'] = {start},
    status =	{help = 'Command to check the status of the service, for Sys V init.',},
    stop =	{help = 'Command to stop the service, for Sys V init.',},
    install =
    {
	help = 'Command to install polygLua.lua',
	func = function(self, options, a, args, i)
	    local w = _.who
	    local d = _.pwd
	    if 'root' ~= w then
		E'Need to be root user to install.'
	    else
		P('not INSTALLING!!!')
--[=[
		P('INSTALLING!!!')
		__[[
#!/bin/bash
		    echo "Installing polygLua"
		    ./polygLua.lua -vvvv
		]]:log():show():Do()
]=]
	    end
	    os.exit(0)
	end
    },
}
options['restart'] = options.start
options['force-reload'] = options.start

P(_.table2string(arg, 'arg'))
P('start = ' .. options.start.value)
_.parse(arg, options, 'polygLua_test')
P('start = ' .. options.start.value)
--P('stop = ' .. options.stop.value)

C'After parse.'
E'After parse.'
W'After parse.'
T'After parse.'
I'After parse.'
D'After parse.'


__[[
    echo -n "This'll print forking later.  "
    date
    sleep 2
]]:log():show():fork('echo -n "later is "; date')
P('')
P('')


local GUI = 'qjackctl'
if _.runnable'catia' then GUI = 'catia' end
P('' .. GUI)
P''

for i,l in ipairs(__'uname -a\nfree -h':log():Do().lines) do
    P(l)
end
__'uname -a':log():Then'free -h':show():Do()
__{'uname -a', 'free -h'}:log():show():Do()
P''


P(__[[
#!/bin/NoSuchCommand
    echo "Should not print."
]]:log():show():Do().status)

P(__[[
#!/usr/bin/env bash
    echo "G'day world from bash."
    exit 42
]]:log():show():Do().status)

P(__[[
#!/usr/bin/env tcc -run
    #include <tcclib.h>

    int main()
    {
	printf("G'day world from C.\n");
	exit(42);
    }
]]:log():show():Do().status)

P(__[[
#!/usr/bin/env tcc -run
    #include <tcclib.h>

    int main()
    {
	printf("G'day world from C.\n");
	return 42;
    }
]]:log():show():Do().status)

P(__[[
#!/usr/bin/env luajit
    print("G'day " .. "world " .. [=[from]=] .. ' Lua.')
    os.exit(42)
]]:log():show():Do().status)

__[[
#!/usr/bin/env perl
    print "G'day world from perl.\n";
]]:log():show():Do()

__[[
#!/usr/bin/env php
<?php
    print("G'day world from php.\n");
]]:log():show():Do()

-- Note no indent for Python, coz whitespace is significant.
__[[
#!/usr/bin/env python3
print("G'day world from python.")
]]:log():show():Do()

__[[#!/usr/bin/env ruby
    puts "G'day world from ruby."
]]:log():show():Do()
P''


P(__'true':log():show():Do().status)
P(__'false':log():show():Do().status)
P(__'exit 42':log():show():Do().status)
P(__'return 42':log():show():Do().status)
P(__'command NoSuchCommand':log():show():Do().status)
P''


--__'qpdfview':forkOnce()
--__'qpdfview':forkOnce()


__'date':log():show():Do()
-- Should get that "later" thing printed while the sleep is happening.
__'date; sleep 5; date':log():show():Do()