sandboxos => tildefriends

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3157 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2016-03-12 18:50:43 +00:00
commit 7c6a377c0b
94 changed files with 27121 additions and 0 deletions

7
tests/01-nop Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
cat > test.js << EOF
print("hi");
EOF
$SANDBOXOS test.js

7
tests/02-valgrind Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
cat > test.js << EOF
print("hi");
EOF
valgrind --log-file=$LOGDIR/valgrind.log $SANDBOXOS test.js

19
tests/03-child Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
cat > test.js << EOF
var task = new Task();
task.onExit = function() {
print("child exited");
};
task.activate();
task.execute("child.js").then(function() {
print("child started");
});
EOF
cat > child.js << EOF
print("I am the child process.");
exit(0);
EOF
$SANDBOXOS test.js

27
tests/04-promise Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
cat > test.js << EOF
var task = new Task();
task.activate();
task.execute("child.js").then(function() {
task.getExports().then(function(exports) {
return exports.add(1, 1);
}).then(function(sum) {
if (sum == 2) {
exit(0);
} else {
exit(1);
}
});
});
EOF
cat > child.js << EOF
exports = {
add: function(left, right) {
return left + right;
}
}
EOF
$SANDBOXOS test.js

26
tests/05-promise-remote-throw Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
cat > test.js << EOF
var task = new Task();
task.activate();
task.execute("child.js").then(function() {
task.getExports().then(function(exports) {
return exports.add(1, 1);
}).then(function(sum) {
exit(1);
}).catch(function(error) {
print("Caught: " + error.message);
exit(0);
});
});
EOF
cat > child.js << EOF
exports = {
add: function(left, right) {
throw new Error("fail");
}
}
EOF
$SANDBOXOS test.js

80
tests/06-restartTask Executable file
View File

@ -0,0 +1,80 @@
#!/bin/bash
mkdir -p packages
for i in filesystem packager; do
ln -s $ROOT/packages/$i packages/$i
done
cp -R $ROOT/packages/system packages/system
mkdir -p packages/test
cat > packages/test/test.js << EOF
print("Hello!");
File.writeFile("packages/hello/hello.js", "this will fail to run!$^!U#%^#$%#%");
var p = imports.system.restartTask("hello");
print("here is our promise: " + p.toString());
print(p);
p.then(function(r) {
print("restart succeeded when it should not have: " + r);
imports.system.finishTest(1);
}).catch(function(e) {
print("restart failed: " + e);
print(e.toString());
for (var i in e) {
print(i);
print(e[i]);
}
imports.system.finishTest(0);
});
EOF
cat > packages/test/package.json << EOF
{
"name": "test",
"start": "test.js",
"trusted": true,
"imports": ["packager", "system"]
}
EOF
cat >> packages/system/system.js << EOF
exports.finishTest = function(result) {
exit(result);
}
EOF
mkdir -p packages/hello
cat > packages/hello/hello.js << EOF
print("Hi.");
EOF
cat > packages/hello/package.json << EOF
{
"name": "hello",
"start": "hello.js"
}
EOF
mkdir -p packages/auth
cat > packages/auth/auth.js << EOF
exports = {
query: function() { return null; },
getCredentials: function() { return {user: 'test', token: 'token'}; },
verifyCredentials: function() { return {permissions: []}; },
};
EOF
cat > packages/auth/package.json << EOF
{
"name": "auth",
"start": "auth.js"
}
EOF
$SANDBOXOS packages/system/system.js

29
tests/07-promise-remote-reject Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
cat > test.js << EOF
var task = new Task();
task.activate();
task.execute("child.js").then(function() {
task.getExports().then(function(exports) {
return exports.add(1, 1);
}).then(function(sum) {
exit(1);
}).catch(function(error) {
print(error);
print("Caught: " + error.message);
exit(0);
});
});
EOF
cat > child.js << EOF
exports = {
add: function(left, right) {
return new Promise(function(resolve, reject) {
reject(new Error("oops"));
});
}
}
EOF
$SANDBOXOS test.js

34
tests/08-database Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
mkdir testdb
cat > test.js << EOF
var db = new Database("testdb");
if (db.get("a")) {
exit(1);
}
db.set("a", 1);
if (db.get("a") != 1) {
exit(1);
}
db.set("b", 2);
db.set("c", 3);
var expected = ['a', 'b', 'c'];
var have = db.getAll();
for (var i = 0; i < have.length; i++) {
var item = have[i];
if (expected.indexOf(item) == -1) {
print("Did not find " + item + " in db.");
exit(2);
} else {
expected.splice(expected.indexOf(item), 1);
}
}
if (expected.length) {
print("Expected but did not find: " + JSON.stringify(expected));
exit(3);
}
EOF
$SANDBOXOS test.js

9
tests/09-this Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
cat > test.js << EOF
var task = new Task();
task.activate.bind(null).apply();
exit(0);
EOF
$SANDBOXOS test.js