├── src ├── service │ ├── lib.mo │ └── BigMap.mo ├── Batch.mo ├── Types.mo └── Eval.mo ├── vessel.json ├── dfx.json ├── package-set.json ├── test ├── BigMapPutGet.log ├── BigMap.mo └── BigMapPutGet.mo ├── .github └── workflows │ └── ci.yml ├── test.sh ├── README.md └── LICENSE /src/service/lib.mo: -------------------------------------------------------------------------------- 1 | import BigMap_ "BigMap"; 2 | module { 3 | public module BigMap = BigMap_; 4 | } 5 | -------------------------------------------------------------------------------- /vessel.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BigTest", 3 | "repo": "git@github.com:dfinity/motoko-bigtest", 4 | "version": "v0.0.1", 5 | "dependencies": ["base", "crud"] 6 | } 7 | -------------------------------------------------------------------------------- /dfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "canisters": { 3 | "BigMap": { 4 | "main": "test/BigMap.mo" 5 | }, 6 | "BigMapPutGet": { 7 | "main": "test/BigMapPutGet.mo" 8 | } 9 | }, 10 | "defaults": { 11 | "build": { 12 | "packtool": "vessel sources", 13 | "output": "canisters/" 14 | }, 15 | "start": { 16 | "address": "127.0.0.1", 17 | "port": 8000 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /package-set.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "base", 4 | "repo": "https://github.com/dfinity/motoko-base", 5 | "version": "master", 6 | "dependencies": [] 7 | }, 8 | { 9 | "name": "crud", 10 | "repo": "https://github.com/matthewhammer/motoko-crud", 11 | "version": "master", 12 | "dependencies": [] 13 | }, 14 | { 15 | "name": "SHA256", 16 | "repo": "https://github.com/matthewhammer/motoko-sha", 17 | "version": "master", 18 | "dependencies": ["base"] 19 | }, 20 | { 21 | "name": "bigmap", 22 | "repo": "git@github.com:dfinity/motoko-bigmap.git", 23 | "version": "master", 24 | "dependencies": ["base", "SHA256"] 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /test/BigMapPutGet.log: -------------------------------------------------------------------------------- 1 | ( 2 | vec { 3 | record { 4 | variant { put = record { vec { 0 }; vec { 0 } } }; 5 | variant { ok = variant { unit } }; 6 | }; 7 | record { 8 | variant { get = vec { 0 } }; 9 | variant { ok = variant { optt = variant { "nat" = 0 } } }; 10 | }; 11 | record { 12 | variant { put = record { vec { 0 }; vec { 0 } } }; 13 | variant { ok = variant { unit } }; 14 | }; 15 | record { 16 | variant { put = record { vec { 1 }; vec { 1 } } }; 17 | variant { ok = variant { unit } }; 18 | }; 19 | record { 20 | variant { get = vec { 0 } }; 21 | variant { ok = variant { optt = variant { "nat" = 0 } } }; 22 | }; 23 | record { 24 | variant { get = vec { 1 } }; 25 | variant { ok = variant { optt = variant { "nat" = 1 } } }; 26 | }; 27 | }, 28 | ) 29 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: "build" 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | jobs: 8 | tests: 9 | runs-on: ubuntu-18.04 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: "install dfx" 13 | run: | 14 | wget https://sdk.dfinity.org/install.sh 15 | echo DFX_VERSION=0.6.0 16 | yes Y | DFX_VERSION=0.6.0 sh install.sh 17 | echo "::add-path::/home/runner/bin" 18 | - name: "dfx cache install" 19 | run: dfx cache install 20 | - name: "install vessel" 21 | run: wget --output-document /home/runner/bin/vessel https://github.com/kritzcreek/vessel/releases/download/v0.4.1/vessel-linux64 && chmod +x /home/runner/bin/vessel 22 | - name: "install candid tool" 23 | run: wget --output-document /home/runner/bin/candiff https://github.com/dfinity/candid/releases/download/2020-09-02/candiff-linux64 && chmod +x /home/runner/bin/candiff 24 | - name: "candiff help (sanity check)" 25 | run: candiff --help 26 | - name: "install didc tool" 27 | run: wget --output-document /home/runner/bin/didc https://github.com/dfinity/candid/releases/download/2020-09-02/didc-linux64 && chmod +x /home/runner/bin/didc 28 | - name: "didc help (sanity check)" 29 | run: didc --help 30 | - name: "test" 31 | run: ./test.sh -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | echo PATH = $PATH 2 | echo vessel @ `which vessel` 3 | 4 | echo 5 | echo == Build. 6 | echo 7 | 8 | dfx start --background 9 | dfx canister create --all 10 | dfx build 11 | 12 | echo 13 | echo == Start BigMap service. 14 | echo 15 | 16 | dfx canister install BigMap 17 | 18 | echo 19 | echo == Test BigMap service. 20 | echo 21 | 22 | dfx canister install BigMapPutGet 23 | 24 | LOOP="(true)"; 25 | while [ "$LOOP" == "(true)" ]; do 26 | LOOP=$(dfx canister call BigMapPutGet doNextCall) 27 | done 28 | 29 | dfx canister call BigMapPutGet getFullLog --output raw > BigMapPutGet.raw 30 | 31 | echo BEGIN BigMapPutGet.raw 32 | cat BigMapPutGet.raw 33 | echo END BigMapPutGet.raw 34 | 35 | echo BEGIN 'cat .dfx/local/canisters/BigMapPutGet/BigMapPutGet.did' 36 | cat .dfx/local/canisters/BigMapPutGet/BigMapPutGet.did 37 | echo END 38 | 39 | echo BEGIN 'didc decode `cat BigMapPutGet.raw` > BigMapPutGet.log' 40 | didc decode `cat BigMapPutGet.raw` -d .dfx/local/canisters/BigMapPutGet/BigMapPutGet.did -m getFullLog > BigMapPutGet.log 41 | echo END 'didc decode `cat BigMapPutGet.raw`' 42 | 43 | echo BEGIN "BigMapPutGet.log (latest-captured log)" 44 | cat BigMapPutGet.log 45 | echo END "BigMapPutGet.log" 46 | 47 | echo BEGIN "test/BigMapPutGet.log (expected log)" 48 | cat test/BigMapPutGet.log 49 | echo END "test/BigMapPutGet.log" 50 | 51 | echo BEGIN "didc diff compares a expected log (left) and latest captured log (right):" 52 | didc diff "`cat test/BigMapPutGet.log`" "`cat BigMapPutGet.log`" 53 | echo END candiff comparison. 54 | 55 | # to do for candiff -- fix this so that it works (under some flags?) like `didc diff` above. 56 | # 57 | # echo BEGIN "candiff compares a expected log (left) and latest captured log (right):" 58 | # candiff diff "`cat test/BigMapPutGet.log`" "`cat BigMapPutGet.log`" 59 | # echo END candiff comparison. 60 | -------------------------------------------------------------------------------- /src/service/BigMap.mo: -------------------------------------------------------------------------------- 1 | // to do -- Refer to a multi-project canister setup somehow? 2 | // for now, we implement a dummy version of BigMap here, in this project. 3 | import BigMap "canister:BigMap"; 4 | 5 | import Prim "mo:prim"; 6 | 7 | //import Debug "../DebugOff"; 8 | import Debug "mo:base/Debug"; 9 | 10 | import Types "../Types"; 11 | 12 | /** isolates logic specific to calling BigMap's service interface 13 | from within the (more general) DSL expression language. */ 14 | module { 15 | 16 | public func awaitt(c: Types.CallReq) : () -> async Types.Res { 17 | func () : async Types.Res = async { 18 | Debug.print ("BigTest.Call.awaitt " # (debug_show c)); 19 | switch c { 20 | case (#put(k, v)) { 21 | await BigMap.put(k, v); 22 | #ok(#unit) 23 | }; 24 | case (#get(k)) { 25 | let res = await BigMap.get(k); 26 | switch res { 27 | case null { #ok(#nulll) }; 28 | case (?r) { #ok(#optt(fromNat8s(r))) }; 29 | } 30 | }; 31 | } 32 | } 33 | }; 34 | 35 | // convert DSL-level arguments into Candid-level arguments 36 | public func callRequest(c: Types.CallExp) : Types.CallReq { 37 | switch c { 38 | case (#put(#value(k), #value(v))) { 39 | let wsk = intoNat8s(k); 40 | let wsv = intoNat8s(v); 41 | #put(wsk, wsv) 42 | }; 43 | case (#get(#value(k))) { 44 | let wsk = intoNat8s(k); 45 | #get(wsk) 46 | }; 47 | case _ { 48 | assert false; loop { } 49 | } 50 | } 51 | }; 52 | 53 | public func intoNat8s(v:Types.Val) : [Nat8] { 54 | switch v { 55 | case (#nat(n)) { [Prim.natToNat8(n)] }; 56 | case (_) { 57 | // todo -- handle more cases 58 | assert false; loop { } 59 | }; 60 | } 61 | }; 62 | 63 | public func fromNat8s(ws:[Nat8]) : Types.Val { 64 | assert (ws.size() == 1); 65 | #nat(Prim.nat8ToNat(ws[0])) 66 | }; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /test/BigMap.mo: -------------------------------------------------------------------------------- 1 | /* TEMP file 2 | 3 | Demonstrates a minimal BigMap service via the Motoko CRUD package. 4 | 5 | to do -- Replace with the real BigMap service, when available. 6 | */ 7 | 8 | import Order "mo:base/Order"; 9 | import Nat "mo:base/Nat"; 10 | import Prim "mo:prim"; 11 | 12 | import Database "mo:crud/Database"; 13 | 14 | actor { 15 | public type Key = [Nat8]; 16 | public type Val = [Nat8]; 17 | 18 | var nextKey : ?[Nat8] = null; 19 | 20 | func keyEqual(x : Key, y : Key) : Bool { 21 | switch (keyCompare(x, y)) { 22 | case (#equal) true; 23 | case _ false; 24 | } 25 | }; 26 | 27 | // to do -- add a generic version to base package 28 | func keyCompare(x : Key, y : Key) : Order.Order { 29 | switch (Nat.compare(x.size(), y.size())) { 30 | case (#less) #less; 31 | case (#greater) #greater; 32 | case (#equal) { 33 | for (i in x.keys()) { 34 | if (x[i] < y[i]) return #less 35 | else if (x[i] > y[i]) return #greater 36 | else { } 37 | }; 38 | return #equal 39 | }; 40 | } 41 | }; 42 | 43 | func keyHash(x : Key) : Word32 { 44 | let blowup : Nat8 -> Word32 = func (x) { 45 | Prim.natToWord32(Prim.nat8ToNat(x)) 46 | }; 47 | // to do -- use all bits in the final hash, not just the first ones 48 | switch (x.size()) { 49 | case 0 0; 50 | case 1 blowup(x[0]); 51 | case 2 { blowup(x[0]) << 0 + 52 | blowup(x[1]) << 8 }; 53 | case 3 { blowup(x[0]) << 0 + 54 | blowup(x[1]) << 8 + 55 | blowup(x[2]) << 16 }; 56 | case _ { 57 | blowup(x[0]) << 24 + 58 | blowup(x[1]) << 16 + 59 | blowup(x[2]) << 8 + 60 | blowup(x[3]) 61 | } 62 | } 63 | }; 64 | 65 | var db = Database.Database( 66 | func (_, _) : Key { 67 | switch nextKey { 68 | case null { assert false; loop { } }; 69 | case (?x) x 70 | }}, 71 | keyEqual, 72 | #hash(keyHash), 73 | ); 74 | 75 | public func put(k:Key, v:Val) : async () { 76 | // to do -- for now, we communicate the key via mutation (ugly). 77 | nextKey := ?k; 78 | let _ = db.create(v); 79 | }; 80 | 81 | public func get(k:Key) : async ?Val { 82 | switch (db.read(k)) { 83 | case (#ok(v)) ?v; 84 | case (#err(_)) null; 85 | } 86 | }; 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/Batch.mo: -------------------------------------------------------------------------------- 1 | import Eval "Eval"; 2 | import Types "Types"; 3 | import Q "mo:base/Deque"; 4 | import List "mo:base/List"; 5 | 6 | //import Debug "../DebugOff"; 7 | import Debug "mo:base/Debug"; 8 | 9 | module { 10 | public class Batch() { 11 | 12 | public type State = Types.State; 13 | 14 | var states : Q.Deque = (null, null); 15 | 16 | public func push(e: Types.Exp) : () { 17 | let st = Types.Init.empState(?e); 18 | states := Q.pushBack(states, st); 19 | }; 20 | 21 | public func peek() : ?Types.DebugInfo { 22 | let s : ?State = Q.peekFront(states); 23 | switch s { 24 | case null null; 25 | case (?s) ?(s.stack, s.env, s.exp); 26 | } 27 | }; 28 | 29 | public func saveResult(res: Types.Res) { 30 | let state : State = 31 | switch (Q.peekFront(states)) { 32 | case null { assert false; loop { } }; 33 | case (?s) { s }; 34 | }; 35 | switch (res, state.exp) { 36 | case (#ok(v), null) { 37 | state.exp := ?#value(v) 38 | }; 39 | case (#err(e), _) { 40 | assert false; loop { } 41 | }; 42 | case (_, ?exp) { 43 | assert false; loop { } 44 | } 45 | }; 46 | }; 47 | 48 | public func nextCallRequest() : ?Types.CallReq { 49 | loop { 50 | let state : State = 51 | switch (Q.peekFront(states)) { 52 | case null { return null }; // end loop 53 | case (?s) s; 54 | }; 55 | Debug.print ("BigTest.Batch.nextCallRequest - state.stack = " # (debug_show state.stack)); 56 | Debug.print ("BigTest.Batch.nextCallRequest - state.env = " # (debug_show state.env)); 57 | Debug.print ("BigTest.Batch.nextCallRequest - state.exp = " # (debug_show state.exp)); 58 | Debug.print ("BigTest.Batch.nextCallRequest - begin evaluation ..."); 59 | let r = Eval.evalState(state); 60 | Debug.print ("BigTest.Batch.nextCallRequest - end evaluation."); 61 | Debug.print ("BigTest.Batch.nextCallRequest - result=" # (debug_show r)); 62 | switch r { 63 | case (#ok(v)) { 64 | Debug.print ("Batch.nextCallRequest - postEval - result=" # (debug_show r)); 65 | switch (Q.popFront(states)) { 66 | case null { assert false }; 67 | case (?(_, q)) { states := q }; 68 | }; 69 | }; 70 | case (#err(#callRequest(stack, call))) { 71 | state.stack := stack; 72 | state.env := Types.Init.empEnv(); 73 | state.exp := null; 74 | return ?call // end loop 75 | }; 76 | case (#err(e)) { 77 | // to do -- report errror 78 | // continue? 79 | assert false; loop { } 80 | } 81 | }; 82 | }; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /test/BigMapPutGet.mo: -------------------------------------------------------------------------------- 1 | import Prim "mo:prim"; 2 | import BigMap "canister:BigMap"; 3 | import Iter "mo:base/Iter"; 4 | import Debug "mo:base/Debug"; 5 | import Buffer "mo:base/Buffer"; 6 | 7 | import TestBatch "../src/Batch"; 8 | import TestTypes "../src/Types"; 9 | import TestCall "../src/service/BigMap"; 10 | 11 | actor { 12 | 13 | // Test "PutGet" as a BigTest program (compare to test/PutGet.mo) 14 | func putGetTestExp(size : Nat) : TestTypes.Exp = { 15 | let s = (debug_show size); 16 | #labell( 17 | "PutGet", 18 | ?("range of (0, " # s # ") puts, followed by the same range of assert'ed gets"), 19 | #block( 20 | [ 21 | ("buf", #range(0, size)), 22 | ("_", #iterate(#varr("buf"), "i", 23 | #call(#put(#varr("i"), #varr("i"))) 24 | )), 25 | ("_", #iterate(#varr("buf"), "i", 26 | #block( 27 | [ 28 | ("x", #call(#get(#varr("i")))), 29 | ("_", #assertt(#equal(#optt(#varr("i")), #varr("x")))) 30 | ]) 31 | )), 32 | ])) 33 | }; 34 | 35 | // ----- Boiler-plate testing code below 36 | 37 | // create a big batch of smaller batches 38 | func newBatches(sizes : [Nat]) : TestBatch.Batch { 39 | let batch = TestBatch.Batch(); 40 | for (c in sizes.vals()) { 41 | batch.push(putGetTestExp(c)); 42 | }; 43 | batch 44 | }; 45 | 46 | // some defaults 47 | var batch : TestBatch.Batch = newBatches([0, 1 48 | //,2, 4, 8 -- TEMP -- make this faster for CI iteration... 49 | //,128 -- takes an hour or so 50 | ]); 51 | 52 | public func reset(sizes : [Nat]) : async () { 53 | batch := newBatches(sizes) 54 | }; 55 | 56 | public func extend(sizes: [Nat]) { 57 | for (s in sizes.vals()) { 58 | batch.push(putGetTestExp(s)); 59 | }; 60 | }; 61 | 62 | public query func peek() : async ?TestTypes.DebugInfo { 63 | batch.peek() 64 | }; 65 | 66 | // false => no next call, otherwise returns true 67 | public func doNextCall() : async Bool { 68 | switch (batch.nextCallRequest()) { 69 | case null { false }; 70 | case (?c) { 71 | Debug.print "doNextCall begin"; 72 | Debug.print ("doNextCall - call = " # (debug_show c)); 73 | Debug.print "doNextCall - awaiting result..."; 74 | let r = await (TestCall.awaitt(c)()); 75 | Debug.print ("doNextCall - result = " # (debug_show r)); 76 | Debug.print "doNextCall - saving result..."; 77 | batch.saveResult(r); 78 | callLog.add((c, r)); 79 | Debug.print "doNextCall end"; 80 | true 81 | } 82 | } 83 | }; 84 | 85 | public type CallReq = TestTypes.CallReq; 86 | public type CallRes = TestTypes.Res; 87 | public type CallLog = [(CallReq, CallRes)]; 88 | 89 | var callLog : Buffer.Buffer<(CallReq, CallRes)> = Buffer.Buffer(0); 90 | 91 | public func getFullLog () : async CallLog { 92 | callLog.toArray() 93 | }; 94 | 95 | // Bonus: 96 | // For testing in an open, interactive world: 97 | // Use this to add other tests not-yet expressed above! 98 | public func pushExp(e: TestTypes.Exp) { 99 | batch.push(e) 100 | }; 101 | 102 | } 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BigTest 2 | 3 | ![build](https://github.com/matthewhammer/motoko-bigtest/workflows/build/badge.svg) 4 | 5 | BigTest expresses and performs _very long-running_ batches of tests that 6 | exercise services on the Internet Computer. 7 | 8 | To use BigTest, the test author expresses each test script as a 9 | program written in a domain specific language (DSL). 10 | 11 | For Motoko programmers, BigTest provides a `Batch` class to build 12 | flexible test actors that test a specific service extensively, but 13 | without running out of gas, or out of time. 14 | 15 | BigTest implements this DSL in Motoko using standard PL implementation 16 | techniques that permit the DSL evaluation to implicitly **suspend** 17 | and **resume** around each remote Internet Computer service call. 18 | 19 | ## BigTest expression language 20 | 21 | The BigTest expression language is general enough for many kinds of tests: 22 | 23 | - **Standard PL features**: iteration, let-binding, primitive data 24 | - **Calls** to the service in question (e.g., `put` and `get` on `BigMap`) 25 | - **Buffers** and generators for test input and output 26 | - **Equivalence** checks for all test data output 27 | - **Assertions** whose failure signals a testing failure 28 | - **Labels** for human-readable reports, documentation and logs 29 | 30 | ## Why? 31 | 32 | Today, we can use shell scripts to invoke `dfx canister call` many times. 33 | 34 | **Q** _Why not use a shell script to create long-running tests?_ 35 | 36 | This is certainly possible, and we do this today. Eventually, 37 | however, **programs that test canisters should _themselves_ be 38 | programmed as canisters**, not shell scripts running on traditional CI 39 | systems. 40 | 41 | To reach this goal, we need a new test-scripting language, as those 42 | shell scripts do not run on the Internet Computer, and probably will 43 | not soon. Unlike shell scripts, the BigTest language does not assume 44 | a filesystem, or any ambient UNIX system. Rather, it only 45 | assumes a Motoko runtime environment, provided by the IC itself. 46 | 47 | With BigTest, we can: 48 | 49 | - Host test logic on the Internet Computer itself, 50 | - Ask the test canister what script its running, what progress there is, etc 51 | - Reuse the same dead simple shell script (one single loop, with one call) 52 | - [(Eventually,) pre-check scripts for sanity, errors, etc](https://arxiv.org/pdf/1608.06012.pdf) 53 | 54 | 55 | **Q:** _Why not write testing canisters directly in Rust, or in Motoko?_ 56 | 57 | This works fine for small tests that exercise the IC minimally, with a 58 | small number of service calls. Let's call these "small batch tests". 59 | 60 | But how do we relate these small batches, or systematically combine 61 | them into large ones? 62 | 63 | To ask it another way, how do we _systematically decompose a big test 64 | batch_ into many very small ones? 65 | 66 | To solve this problem, we need techniques that _stream_ the behavior 67 | of the batch test, and keep it "live" across many separate activating 68 | ingress calls. This way, a big batch can be decomposed (via 69 | streaming) into many small batches. 70 | 71 | This is precisely the problem solved by the BigTest DSL evaluator. 72 | 73 | Notably, it's also solved by languages that implement an `async` 74 | abstraction. More below. 75 | 76 | 77 | ### Aside: Static versus dynamic PL techniques 78 | 79 | Why even implement this new language if we already have Rust and Motoko? 80 | 81 | In terms of language design, Motoko programs and BigTest programs are 82 | attacking similar problems. 83 | 84 | In both settings, interacting with the Internet Computer interrupts 85 | ordinary control flow constructs, like simple loops, and the language 86 | uses techniques to hide this interruption from programmers, who do not 87 | wish to express it directly in their source programs. In sum, both 88 | languages express programs whose IC service calls require saving and 89 | restoring a surrounding calling context. 90 | 91 | Of course, the BigTest system is itself expressed as a Motoko program. 92 | 93 | Unlike _Motoko programs_, _BigTest programs are Motoko data_, and can 94 | be sent in a message or received as a response. 95 | 96 | Further, unlike a Rust or Motoko program, a BigTest program can be 97 | inspected and manipulated dynamically in a totally straightforward 98 | way, permitting tests to (potentially) be viewed, changed or extended 99 | while they are running. 100 | 101 | Stepping back, these benefits are merely those of dynamic PL 102 | techniques over static ones. 103 | 104 | BigTest would also benefit from additional (currently missing) static 105 | techniques, such as a type system for doing sanity checks. 106 | 107 | [Eventually, enough static checks would render BigTest more like Motoko 108 | and Rust, which is not the goal.](https://arxiv.org/pdf/1608.06012.pdf) 109 | -------------------------------------------------------------------------------- /src/Types.mo: -------------------------------------------------------------------------------- 1 | import List "mo:base/List"; 2 | import AssocList "mo:base/AssocList"; 3 | import Result "mo:base/Result"; 4 | import Buffer "mo:base/Buffer"; 5 | import Text "mo:base/Text"; 6 | import Iter "mo:base/Iter"; 7 | 8 | module { 9 | 10 | // calls to test: Specialized to BigMap actor (for now). 11 | public type CallExp = { 12 | #put: (Exp, Exp); 13 | #get: Exp; 14 | }; 15 | 16 | // when well-formed, each call expression resolves to call request. 17 | public type CallReq = { 18 | #put: ([Nat8], [Nat8]); 19 | #get: [Nat8]; 20 | }; 21 | 22 | // ----- The rest of this module is generic, and not specific to BigMap's API. 23 | 24 | // express the "high-level" testing logic with a Motoko DSL; 25 | // expressions relate multiple Calls, and form tests around them. 26 | public type Exp = { 27 | #call: CallExp; 28 | #arms: [Exp]; // one assert(false) permitted per "arm" 29 | #labell: (Text, ?Text, Exp); // (label, description, body) for reports, docs, and log output 30 | #equal: (Exp, Exp); // considers buffer ids, and ignores content 31 | #equiv: (Exp, Exp); // ignores buffer ids, and considers content 32 | #assertt: Exp; // assert false stops execution in this "arm" 33 | #varr: Text; // resolve vars introduced by #block 34 | #buf: [Exp]; // allocate a new buffer 35 | #range: (Nat, Nat); // buffer all numbers in given range 36 | #iterate: (Exp, Text, Exp); // (buffer, var, body) 37 | #block: [Decl]; 38 | #optt: Exp; 39 | #value: Val; 40 | }; 41 | 42 | public type Decl = (Text, Exp); 43 | 44 | // lists are more inductive, and more useful for the stack rep 45 | public type Decls = List.List; 46 | 47 | // In Exp, we use Motoko keywords as variant labels by adding an extra "last letter", which avoids Motoko lexing/parsing issues (e.g., #labell). Rationale: Minimal effect on readability. 48 | 49 | // "high-level" values in/out of the calls to test, and as helper data 50 | public type Val = { 51 | #unit; 52 | #nulll; 53 | #bool: Bool; 54 | #nat: Nat; 55 | #text: Text; // remove? (currently unused) 56 | #buf: Nat; 57 | #optt: Val; 58 | }; 59 | 60 | // Halt for call requests, assertion failures, other errors 61 | public type Halt = { 62 | #callRequest: (Stack, CallReq); 63 | #assertFalse: Exp; 64 | #unboundVariable: (Env, Text); 65 | #iterateNonBuffer: Val; 66 | #assertNonBool: (Env, Exp, Val); 67 | }; 68 | 69 | public type Env = AssocList.AssocList; 70 | 71 | public type Res = Result.Result; 72 | 73 | public type Store = { 74 | bufs: Buffer.Buffer>; 75 | }; 76 | 77 | // remaining work of an Exp to perform later, after a Call 78 | public type Cont = { 79 | #labell: (Text, ?Text); 80 | #block: (Text, List.List<(Text, Exp)>); 81 | #iterate: (Nat, Nat, Text, Exp); // (buf, key, var, body) 82 | #arms: [Exp]; 83 | }; 84 | 85 | public type Frame = (Env, Cont); 86 | public type Stack = List.List; 87 | 88 | // Info for inspecting expression evaluation via `peek` 89 | public type DebugInfo = (Stack, Env, ?Exp); 90 | 91 | public type State = { 92 | store: Store; 93 | var stack: Stack; 94 | var env: Env; 95 | var exp: ?Exp; 96 | }; 97 | 98 | public module Init { 99 | public func empStore() : Store { 100 | { 101 | bufs = Buffer.Buffer>(0); 102 | } 103 | }; 104 | 105 | public func empStack() : Stack { 106 | List.nil() 107 | }; 108 | 109 | public func empEnv() : Env { 110 | List.nil<(Text, Val)>() 111 | }; 112 | 113 | public func empState(_exp: ?Exp) : State { 114 | { 115 | store = empStore(); 116 | var stack = empStack(); 117 | var env = empEnv(); 118 | var exp = _exp; 119 | } 120 | }; 121 | }; 122 | 123 | public module Env { 124 | public func update(env: Env, x:Text, v:Val) : Env { 125 | // remove shadowed variable, if any --- a simple form of GC in the DSL evaluation logic 126 | let (env2, _) = AssocList.replace(env, x, func (x:Text, y:Text) : Bool { x == y }, null); 127 | ?((x, v), env2) 128 | }; 129 | public func find(env: Env, x:Text) : ?Val { 130 | AssocList.find(env, x, func (x:Text, y:Text) : Bool { x == y }) 131 | }; 132 | }; 133 | 134 | public module Val { 135 | public func equiv(store:Store, v1: Val, v2: Val) : Bool { 136 | switch (v1, v2) { 137 | case (#bool(b1), #bool(b2)) b1 == b2; 138 | case (#nat(n1), #nat(n2)) n1 == n2; 139 | case (#text(t1), #text(t2)) t1 == t2; 140 | case (#optt(v1), #optt(v2)) equiv(store, v1, v2); 141 | case (#buf(b1), #buf(b2)) { 142 | if (b1 == b2) { 143 | true 144 | } else { 145 | let buf1 = store.bufs.get(b1); 146 | let buf2 = store.bufs.get(b2); 147 | if (buf1.size() != buf2.size()) 148 | false 149 | else { 150 | if (buf1.size() == 0) { true } else { 151 | for (i in Iter.range(0, buf1.size() - 1)) { 152 | let v1 = buf1.get(i); 153 | let v2 = buf2.get(i); 154 | if (equiv(store, v1, v2)) { 155 | // continue 156 | } else { 157 | return false 158 | } 159 | }; 160 | true 161 | } 162 | } 163 | } 164 | }; 165 | case (_, _) false; 166 | } 167 | }; 168 | public func equal(v1: Val, v2: Val) : Bool { 169 | switch (v1, v2) { 170 | case (#bool(b1), #bool(b2)) b1 == b2; 171 | case (#nat(n1), #nat(n2)) n1 == n2; 172 | case (#text(t1), #text(t2)) t1 == t2; 173 | case (#buf(b1), #buf(b2)) b1 == b2; 174 | case (#optt(v1), #optt(v2)) equal(v1, v2); 175 | case (_, _) false; 176 | }; 177 | }; 178 | }; 179 | } 180 | -------------------------------------------------------------------------------- /src/Eval.mo: -------------------------------------------------------------------------------- 1 | import Iter "mo:base/Iter"; 2 | import Buffer "mo:base/Buffer"; 3 | import List "mo:base/List"; 4 | 5 | import Types "Types"; 6 | import CallBigMap "service/BigMap"; 7 | 8 | //import Debug "../DebugOff"; 9 | import Debug "mo:base/Debug"; 10 | 11 | import Log "mo:base/Debug"; 12 | 13 | module { 14 | 15 | public type State = Types.State; 16 | public type Store = Types.Store; 17 | public type Stack = Types.Stack; 18 | public type Env = Types.Env; 19 | public type Cont = Types.Cont; 20 | public type Frame = Types.Frame; 21 | public type Exp = Types.Exp; 22 | public type Res = Types.Res; 23 | public type Val = Types.Val; 24 | public type Decls = Types.Decls; 25 | 26 | // evaluate all stack frames, or until we reach a call (then suspend), or an error 27 | public func evalState(state: State) : Res { 28 | switch (state.exp) { 29 | case null { assert false; loop {}}; 30 | case (?exp) { 31 | switch (eval(state.store, state.env, exp)) { 32 | case (#ok(v)) { evalStack(state.store, state.stack, v) }; 33 | case (#err(#callRequest(stack, call))) { 34 | let s = List.append(List.reverse(stack), state.stack); 35 | #err(#callRequest(s, call)) 36 | }; 37 | case (#err(e)) { #err(e) }; 38 | } 39 | }; 40 | } 41 | }; 42 | 43 | // evaluate all stack frames, or until we reach a call (then suspend), or an error 44 | public func evalStack(store: Store, stack:Stack, v: Val) : Res { 45 | switch stack { 46 | case null { #ok(v) }; 47 | case (?(frame, stack)) { 48 | switch frame { 49 | case (env, (#labell(name, desc))) { 50 | Log.print ("BigTest.Eval.evalStack - Successful test, returning value " # (debug_show v)); 51 | Log.print ("BigTest.Eval.evalStack - name = " # name); 52 | Log.print ("BigTest.Eval.evalStack - desc = " # (debug_show desc)); 53 | evalStack(store, stack, v) 54 | }; 55 | case (env, (#block(x, decls))) { 56 | Debug.print ("BigTest.Eval.evalStack - " # x # " := " # (debug_show v)); 57 | let env2 = Types.Env.update(env, x, v); 58 | switch (evalBlock(store, env2, decls)) { 59 | case (#err(#callRequest(stack2, call))) { 60 | #err(#callRequest(List.append(List.reverse(stack2), stack), call)) 61 | }; 62 | case (#err(e)) #err(e); 63 | case (#ok(#unit)) evalStack(store, stack, #unit); 64 | case _ { assert false; loop { }}; 65 | } 66 | }; 67 | case (env, (#iterate(b, i, x, body))) { 68 | switch (evalIterate(store, env, b, i, x, body)) { 69 | case (#err(#callRequest(stack2, call))) { 70 | #err(#callRequest(List.append(List.reverse(stack2), stack), call)) 71 | }; 72 | case (#err(e)) #err(e); 73 | case (#ok(#unit)) evalStack(store, stack, #unit); 74 | case _ { assert false; loop { }}; 75 | } 76 | }; 77 | case _ { 78 | // to do -- finish missing cases 79 | assert false; loop { } 80 | }; 81 | } 82 | }; 83 | } 84 | }; 85 | 86 | // evaluate expression, or until we reach a call (then suspend), or an error 87 | public func eval(store: Store, env: Env, exp: Exp) : Res { 88 | switch exp { 89 | case (#value v) { #ok(v) }; 90 | case (#optt e) { 91 | switch (eval(store, env, e)) { 92 | case (#ok(v)) { #ok(#optt(v)) }; 93 | case (#err(e)) { #err(e) }; 94 | } 95 | }; 96 | case (#call(#put(e1, e2))) { 97 | let r1 = eval(store, env, e1); 98 | let r2 = eval(store, env, e2); 99 | switch (r1, r2) { 100 | case (#ok(v1), #ok(v2)) { 101 | #err( 102 | #callRequest( 103 | Types.Init.empStack(), 104 | CallBigMap.callRequest( 105 | #put(#value(v1), 106 | #value(v2))))) 107 | }; 108 | case (#err(e1), _) #err(e1); 109 | case (_, #err(e2)) #err(e2); 110 | } 111 | }; 112 | case (#call(#get(e))) { 113 | let r = eval(store, env, e); 114 | switch r { 115 | case (#ok(v)) { 116 | #err( 117 | #callRequest( 118 | Types.Init.empStack(), 119 | CallBigMap.callRequest( 120 | #get(#value(v)) 121 | ))) 122 | }; 123 | case (#err(e)) #err(e); 124 | } 125 | }; 126 | case (#varr x) { 127 | switch (Types.Env.find(env, x)) { 128 | case null #err(#unboundVariable(env, x)); 129 | case (?v) { #ok(v) }; 130 | } 131 | }; 132 | case (#iterate(buf, x, body)) { 133 | switch (eval(store, env, buf)) { 134 | case (#ok(#buf(b))) { 135 | evalIterate(store, env, b, 0, x, body) 136 | }; 137 | case (#ok(v)) #err(#iterateNonBuffer(v)); 138 | case (#err(e)) #err(e); 139 | }; 140 | }; 141 | case (#labell(name, desc, e)) { 142 | Log.print "BigTest.Eval.evalExp - Begin labeled test:"; 143 | Log.print ("BigTest.Eval.evalExp - name = " # name); 144 | Log.print ("BigTest.Eval.evalExp - desc = " # (debug_show desc)); 145 | switch (eval(store, env, e)) { 146 | case (#ok(v)) { #ok(v) }; 147 | case (#err(#callRequest(stack, call))) { 148 | Log.print ( 149 | "BigTest.Eval.evalExp - Interrupting test " # name # 150 | " for call request " # (debug_show call)); 151 | let cont : Cont = #labell(name, desc); 152 | let frame : Frame = (env, cont); 153 | #err(#callRequest(?(frame, stack), call)) 154 | }; 155 | case (#err(e)) { #err(e) }; 156 | } 157 | }; 158 | case (#arms(es)) { 159 | // to do -- sort of like iterate 160 | assert false; loop { } 161 | }; 162 | case (#buf(es)) { 163 | let buf = Buffer.Buffer(0); 164 | for (e in es.vals()) { 165 | switch (eval(store, env, e)) { 166 | case (#err(e)) return #err(e); 167 | case (#ok(v)) buf.add(v); 168 | } 169 | }; 170 | let b = store.bufs.size(); 171 | store.bufs.add(buf); 172 | #ok(#buf(b)) 173 | }; 174 | case (#assertt(e)) { 175 | switch (eval(store, env, e)) { 176 | case (#ok(#bool(b))) { 177 | // in verbose mode, print all true assertions? 178 | if b { #ok(#unit) } else { 179 | // to do -- print error in log, but continue? 180 | assert false; loop { } 181 | } 182 | }; 183 | case (#ok(v)) #err(#assertNonBool(env, e, v)); 184 | case (#err(e)) #err(e); 185 | } 186 | }; 187 | case (#equiv(e1, e2)) { 188 | let r1 = eval(store, env, e1); 189 | let r2 = eval(store, env, e2); 190 | switch (r1, r2) { 191 | case (#ok(v1), #ok(v2)) { 192 | if (Types.Val.equiv(store, v1, v2)) 193 | #ok(#bool(true)) 194 | else 195 | #ok(#bool(false)) 196 | }; 197 | case (#err(e1), _) #err(e1); 198 | case (_, #err(e2)) #err(e2); 199 | } 200 | }; 201 | case (#equal(e1, e2)) { 202 | let r1 = eval(store, env, e1); 203 | let r2 = eval(store, env, e2); 204 | switch (r1, r2) { 205 | case (#ok(v1), #ok(v2)) { 206 | if (Types.Val.equal(v1, v2)) 207 | #ok(#bool(true)) 208 | else 209 | #ok(#bool(false)) 210 | }; 211 | case (#err(e1), _) #err(e1); 212 | case (_, #err(e2)) #err(e2); 213 | } 214 | }; 215 | case (#block decls) { 216 | evalBlock(store, env, List.fromArray(decls)) 217 | }; 218 | case (#range (n, m)) { 219 | let r = Iter.range(n, m); 220 | let buf = Buffer.Buffer(0); 221 | for (i in r) { 222 | buf.add(#nat(i)) 223 | }; 224 | let b = store.bufs.size(); 225 | store.bufs.add(buf); 226 | #ok(#buf(b)) 227 | }; 228 | } 229 | }; 230 | 231 | public func evalIterate(store:Store, env:Env, b:Nat, pos:Nat, x:Text, body:Exp) : Res { 232 | let buf = store.bufs.get(b); 233 | Debug.print ("BigTest.Eval.evalIterate begin " # (debug_show (b, pos, x, body))); 234 | for (i in Iter.range(pos, buf.size() - 1)) { 235 | let v = buf.get(i); 236 | let env2 = Types.Env.update(env, x, v); 237 | switch (eval(store, env2, body)) { 238 | case (#err(#callRequest(stack, call))) { 239 | if (i < buf.size() - 1) { 240 | Debug.print "BigTest.Eval.evalIterate interrupted, saving unfinished iterations"; 241 | let cont = #iterate(b, i + 1, x, body); 242 | let s = ?((env2, cont), stack); 243 | return #err(#callRequest(s, call)) 244 | } else { 245 | Debug.print "BigTest.Eval.evalIterate interrupted on last iteration"; 246 | return #err(#callRequest(stack, call)) 247 | } 248 | }; 249 | case (#err(e)) { return #err(e) }; 250 | case (#ok(_v)) { }; 251 | } 252 | }; 253 | Debug.print "BigTest.Eval.evalIterate end"; 254 | #ok(#unit) 255 | }; 256 | 257 | public func evalBlock(store: Store, env: Env, decls: Decls) : Res { 258 | var env2 = env; 259 | var decls2 = decls; 260 | loop { 261 | switch decls2 { 262 | case null { return #ok(#unit) }; 263 | case (?((x, e), rest)) { 264 | decls2 := rest; 265 | switch (eval(store, env2, e)) { 266 | case (#err(#callRequest(stack, call))) { 267 | // save our place, for later: 268 | let cont = #block(x, rest); 269 | let frame = (env2, cont); 270 | return #err(#callRequest(?(frame, stack), call)) 271 | }; 272 | case (#err(e)) { 273 | return #err(e) 274 | }; 275 | case (#ok(v)) { 276 | Debug.print ("BigTest.Eval.evalBlock - " # x # " := " # (debug_show v)); 277 | env2 := Types.Env.update(env2, x, v) 278 | }; 279 | }; 280 | }; 281 | } 282 | }; 283 | #ok(#unit) 284 | }; 285 | 286 | } // module 287 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------