]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/sandbox/sandbox-tests.factor
5d0496e77bb6e77c746135837d1f738cf1767681
[factor.git] / unmaintained / sandbox / sandbox-tests.factor
1 ! Copyright (C) 2009 Maxim Savchenko
2 ! See http://factorcode.org/license.txt for BSD license.
3
4 USING: kernel accessors continuations lexer vocabs vocabs.parser
5        combinators.short-circuit sandbox tools.test ;
6
7 IN: sandbox.tests
8
9 << "sandbox.syntax" load-vocab drop >>
10 USE: sandbox.syntax.private
11
12 : run-script ( x lines -- y )
13     H{ { "kernel" "kernel" } { "math" "math" } { "sequences" "sequences" } }
14     parse-sandbox call( x -- x! ) ;
15
16 [ 120 ]
17 [
18     5
19     {
20         "! Simple factorial example"
21         "APPLYING: kernel math sequences ;"
22         "1 swap [ 1+ * ] each"
23     } run-script
24 ] unit-test
25
26 [
27     5
28     {
29         "! Jailbreak attempt with USE:"
30         "USE: io"
31         "\"Hello world!\" print"
32     } run-script
33 ]
34 [
35     {
36         [ lexer-error? ]
37         [ error>> condition? ]
38         [ error>> error>> no-word-error? ]
39         [ error>> error>> name>> "USE:" = ]
40     } 1&&
41 ] must-fail-with
42
43 [
44     5
45     {
46         "! Jailbreak attempt with unauthorized APPLY:"
47         "APPLY: io"
48         "\"Hello world!\" print"
49     } run-script
50 ]
51 [
52     {
53         [ lexer-error? ]
54         [ error>> sandbox-error? ]
55         [ error>> vocab>> "io" = ]
56     } 1&&
57 ] must-fail-with