瀏覽代碼

Sol Part 52.2: How To Shoot Git In The Foot!

master
Graham Northup 5 年之前
父節點
當前提交
609a197b5b
簽署人: grissess GPG Key ID: 5D000E6F539376FB
  1. 2
      .gitignore
  2. 1
      programs/a.sol
  3. 1
      programs/b.sol
  4. 7
      programs/http.sol
  5. 55
      programs/package.sol
  6. 7
      programs/server.sol
  7. 29
      tests/_lib.sol
  8. 4
      tests/always_passes.sol
  9. 4
      tests/fails.sol

2
.gitignore

@ -8,7 +8,7 @@ stdout
gclog.txt
gcstat.txt
iss*
*.sol
/*.sol
_build
doxyxml
valgrind.log

1
programs/a.sol

@ -0,0 +1 @@
package:import('b')

1
programs/b.sol

@ -0,0 +1 @@
package:import('a')

7
programs/http.sol

@ -0,0 +1,7 @@
func printerr(a)
io.stderr:write(tostring(a))
end
while 1 do
printerr(io.stdin:read(io.LINE))
end

55
programs/package.sol

@ -0,0 +1,55 @@
-- Simple package manager script
package = {
path = ['./', '/usr/share/sol/'],
extensions = ['.sol', ''],
loaded = {},
loading = {},
load = func(self, file)
result = try(io.open, file, io.MODE_READ)
if !result[0] then return None end
stream = result[1]
program = parse(stream:read(io.ALL))
return self:load_node(program)
end,
load_node = func(self, node)
environ = {}
node(environ)
return environ
end,
import = func(self, name)
if None != self.loading[name] then
error('Already loading: '+name)
end
self.loading[name] = True
if None != self.loaded[name] then return self.loaded[name] end
for path in self.path do
for extension in self.extensions do
module = self:load(path + name + extension)
if None != module then
self.loaded[name] = module
self.loading[name] = None
return module
end
end
end
self.loading[name] = None
error('Module not found')
end,
}
--None -- Separator
func()
stream = try(io.open, '/etc/sol/path', io.MODE_READ)
if stream[0] then
stream = stream[1]
while !stream:eof() do
line = stream:read(io.LINE)
line = line:sub(0, -1)
if #line then
package.path:insert(#package.path, line)
end
end
end
end()

7
programs/server.sol

@ -0,0 +1,7 @@
io.stdin:read(1)
print('HTTP/1.1 200 OK
Content-type: text/plain
Hello from Sol!')

29
tests/_lib.sol

@ -0,0 +1,29 @@
func assert(x, msg)
if !x then
error("Assertion failed: " + tostring(msg))
end
end
func assert_eq(x, y, msg)
assert(x == y, msg)
end
func assert_none(x, msg)
assert_eq(None, x, msg)
end
func assert_not_none(x, msg)
assert(None != x, msg)
end
func warn(msg)
io.stderr:write("Warning: " + tostring(msg) + "\n")
end
func warn_if(cond, msg)
if cond then
warn(msg)
end
end
print("(test library loaded successfully)")

4
tests/always_passes.sol

@ -0,0 +1,4 @@
execfile("tests/_lib.sol")
-- Exit successfully
return 0

4
tests/fails.sol

@ -0,0 +1,4 @@
execfile("tests/_lib.sol")
-- Exit with failure
return 254
Loading…
取消
儲存