Browse Source

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

Graham Northup 5 years ago
parent
commit
609a197b5b
Signed by: Grissess <grissess@nexusg.org> GPG Key ID: 5D000E6F539376FB
9 changed files with 109 additions and 1 deletions
  1. 1
    1
      .gitignore
  2. 1
    0
      programs/a.sol
  3. 1
    0
      programs/b.sol
  4. 7
    0
      programs/http.sol
  5. 55
    0
      programs/package.sol
  6. 7
    0
      programs/server.sol
  7. 29
    0
      tests/_lib.sol
  8. 4
    0
      tests/always_passes.sol
  9. 4
    0
      tests/fails.sol

+ 1
- 1
.gitignore View File

@@ -8,7 +8,7 @@ stdout
8 8
 gclog.txt
9 9
 gcstat.txt
10 10
 iss*
11
-*.sol
11
+/*.sol
12 12
 _build
13 13
 doxyxml
14 14
 valgrind.log

+ 1
- 0
programs/a.sol View File

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

+ 1
- 0
programs/b.sol View File

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

+ 7
- 0
programs/http.sol View File

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

+ 55
- 0
programs/package.sol View File

@@ -0,0 +1,55 @@
1
+-- Simple package manager script
2
+
3
+package = {
4
+	path = ['./', '/usr/share/sol/'],
5
+	extensions = ['.sol', ''],
6
+	loaded = {},
7
+	loading = {},
8
+	load = func(self, file)
9
+		result = try(io.open, file, io.MODE_READ)
10
+		if !result[0] then return None end
11
+		stream = result[1]
12
+		program = parse(stream:read(io.ALL))
13
+		return self:load_node(program)
14
+	end,
15
+	load_node = func(self, node)
16
+		environ = {}
17
+		node(environ)
18
+		return environ
19
+	end,
20
+	import = func(self, name)
21
+		if None != self.loading[name] then
22
+			error('Already loading: '+name)
23
+		end
24
+		self.loading[name] = True
25
+		if None != self.loaded[name] then return self.loaded[name] end
26
+		for path in self.path do
27
+			for extension in self.extensions do
28
+				module = self:load(path + name + extension)
29
+				if None != module then
30
+					self.loaded[name] = module
31
+					self.loading[name] = None
32
+					return module
33
+				end
34
+			end
35
+		end
36
+		self.loading[name] = None
37
+		error('Module not found')
38
+	end,
39
+}
40
+
41
+--None  -- Separator
42
+
43
+func()
44
+	stream = try(io.open, '/etc/sol/path', io.MODE_READ)
45
+	if stream[0] then
46
+		stream = stream[1]
47
+		while !stream:eof() do
48
+			line = stream:read(io.LINE)
49
+			line = line:sub(0, -1)
50
+			if #line then
51
+				package.path:insert(#package.path, line)
52
+			end
53
+		end
54
+	end
55
+end()

+ 7
- 0
programs/server.sol View File

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

+ 29
- 0
tests/_lib.sol View File

@@ -0,0 +1,29 @@
1
+func assert(x, msg)
2
+	if !x then
3
+		error("Assertion failed: " + tostring(msg))
4
+	end
5
+end
6
+
7
+func assert_eq(x, y, msg)
8
+	assert(x == y, msg)
9
+end
10
+
11
+func assert_none(x, msg)
12
+	assert_eq(None, x, msg)
13
+end
14
+
15
+func assert_not_none(x, msg)
16
+	assert(None != x, msg)
17
+end
18
+
19
+func warn(msg)
20
+	io.stderr:write("Warning: " + tostring(msg) + "\n")
21
+end
22
+
23
+func warn_if(cond, msg)
24
+	if cond then
25
+		warn(msg)
26
+	end
27
+end
28
+
29
+print("(test library loaded successfully)")

+ 4
- 0
tests/always_passes.sol View File

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

+ 4
- 0
tests/fails.sol View File

@@ -0,0 +1,4 @@
1
+execfile("tests/_lib.sol")
2
+
3
+-- Exit with failure
4
+return 254

Loading…
Cancel
Save