annotate core-javascript/testtools.rst @ 201:b6864a86e876 default tip

Przetłumaczone getting-started
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 15 Jul 2012 13:27:27 +0200
parents 71b7fd796ddf
children b04f509bee83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
137
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
1 Test tools
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
2 ==========
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
3
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
4 To make it easier to test code, and to ensure that example code is
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
5 correct, there is a small testtools.js file in the work folder.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
6
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
7
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
8 How to write tests
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
9 ------------------
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
10
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
11 To prepare a test create a file like this. It's also in the work
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
12 folder. (For real examples the file will give *assert* a more
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
13 interesting argument, whose truth or falsity is perhaps not obvious.)
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
14
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
15 .. literalinclude:: /core-javascript-work/demo_testtools.js
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
16 :language: javascript
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
17
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
18
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
19 How to run tests
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
20 ----------------
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
21
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
22 Here's how to run the tests at the command line, finishing with a
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
23 command prompt that allows you inspect the state and also run the test
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
24 again.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
25
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
26
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
27 Rhino
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
28 ^^^^^
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
29
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
30 For Rhino use *load* to run the test again.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
31
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
32 .. code-block:: sh
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
33
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
34 core-javascript-work$ js -f testtools.js -f demo_testtools.js -f -
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
35 Testing: all-pass
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
36 Testing: 2-4-fail
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
37 ! assert 2 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
38 ! assert 4 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
39 Rhino 1.7 release 2 2010 01 20
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
40 js> load('demo_testtools.js') // You type this.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
41 Testing: all-pass
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
42 Testing: 2-4-fail
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
43 ! assert 2 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
44 ! assert 4 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
45 js>
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
46
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
47
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
48 JSDB
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
49 ^^^^
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
50
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
51 For JSDB use *run* to run the test again.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
52
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
53 .. code-block:: sh
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
54
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
55 C:core-javascript-work> jsdb -load testtools.js -load demo_testtools.js
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
56 Testing: all-pass
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
57 Testing: 2-4-fail
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
58 ! assert 2 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
59 ! assert 4 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
60 js> load('demo_testtools.js') // You type this.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
61 Testing: all-pass
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
62 Testing: 2-4-fail
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
63 ! assert 2 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
64 ! assert 4 has failed
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
65 js>
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
66
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
67
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
68 testools.js
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
69 -----------
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
70
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
71 (Optional on a first reading.) Here's the file testools.js. It's
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
72 short and simple (and has a not-nice dependency on global variables).
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
73 It also has a branch based on whether it's being run on JSDB or Rhino.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
74
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
75 .. literalinclude:: /core-javascript-work/testtools.js
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
76 :language: javascript