Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Introduced better test registering:

- Removed Type.test() method for detached tests registering.
- Added handling for inline group tests.
- Added handling for test factories defined inside a group.
- Changed simple name validation - test name can be unselectable but cannot contain dots.
- Changed selection tree generation - now only groups are visible for selection.
  • Loading branch information...
commit 1939d51b0253f5c17f72e93c80560463b49ee663 1 parent 0944f0b
marek-kuzora marek-kuzora authored
113 source/group.coffee
@@ -6,6 +6,15 @@
6 6
7 7
8 8
  9 +# Reserved group properties. Properties defined below will be used to
  10 +# define group parameters, whereas all other group properties will be
  11 +# used to create tests.
  12 +RESERVED = [
  13 + 'after', 'after_each' , 'before', 'before_each' ,
  14 + 'envs', 'generators', 'min_arg', 'run', 'scenario'
  15 +]
  16 +
  17 +
9 18 return class Group extends Node
10 19
11 20 constructor: (name, parent, type, raw = {}) ->
@@ -14,32 +23,97 @@ return class Group extends Node
14 23 # Collection of group nodes.
15 24 @nodes = []
16 25
  26 + # Assert the simple name is selectable.
  27 + if not @_is_selectable(@_simple)
  28 + throw new Error "Simple name '#{@_simple}' is not selectable."
  29 +
  30 + # Update the selection tree.
  31 + parent.get_selection_tree()[@_simple] = @get_selection_tree()
  32 +
  33 + # Create tests from all other not RESERVED properties.
  34 + @_create_tests(raw)
  35 +
  36 +
  37 + #
  38 + # Returns true if the given name matches variable regexp and
  39 + # therefore is selectable.
  40 + #
  41 + # @param name {String}
  42 + # @return {Boolean}
  43 + #
  44 + _is_selectable: (name) ->
  45 + return regexp().VARIABLE.test(name)
  46 +
  47 +
  48 + #
  49 + # Creates group tests from all not RESERVED properties.
  50 + # If raw.generators is defined, generates additional tests using
  51 + # factories for each provided argument.
  52 + #
  53 + # @param raw {Object}
  54 + #
  55 + _create_tests: (raw) ->
  56 +
  57 + # Register inline tests provided in raw hash.
  58 + for name, test in raw when RESERVED.indexOf(k) is -1
  59 + @register_test(name, test)
  60 +
  61 + # Register tests from factories generated using provided arguments.
  62 + for generator in raw.generators
  63 + for argument in generator.args
  64 +
  65 + # Factory must always return a hash of tests.
  66 + for name, test of generator.factory(argument)
  67 + @register_test(name, test)
  68 +
17 69
18 70 #
19 71 # Creates and adds a new group child node. Attaches child node
20 72 # selection tree into the group selection tree. Throws an error
21 73 # if the name is duplicated with any of the existing group nodes.
22 74 #
23   - # @param type {Class} node class type.
24   - # @param name {String} node name.
25   - # @param ttype {String} tests type name.
26   - # @param raw {Object} node definition.
  75 + # @param name {String} group name.
  76 + # @param raw {Object} group definition.
27 77 #
28   - # @return {Node}
  78 + # @return {Group}
29 79 #
30   - add: (type, name, ttype, raw) ->
31   -
  80 + register_group: (name, raw) ->
  81 +
32 82 # Assert the name is unique.
33 83 for n in @nodes when n.name is name
34 84 throw new Error "Node #{name} already exists"
35 85
36 86 # Create new node and push it as a group child.
37   - @nodes.push(n = new type(name, @, ttype, raw))
  87 + @nodes.push(group = new Group(name, @, @_type, raw))
  88 + return group
38 89
39   - # Update the selection tree.
40   - @get_selection_tree()[n.get_simple_name()] = n.get_selection_tree()
41 90
42   - return n
  91 + #
  92 + # Creates and adds a new test child node. Accepts raw as function as
  93 + # a shortcut definition. Throws an error if the name is duplicated
  94 + # with any of the existing group nodes.
  95 + #
  96 + # @param name {String} test name.
  97 + # @param raw {Object} test definition.
  98 + #
  99 + # @return {Test}
  100 + #
  101 + register_test: (name, raw) ->
  102 +
  103 + # Expands the test name.
  104 + name = @get_child_prefix + name
  105 +
  106 + # Expands the shortcut test definition.
  107 + if typeof raw is 'function'
  108 + raw = run: raw
  109 +
  110 + # Assert the name is unique.
  111 + for n in @nodes when n.name is name
  112 + throw new Error "Node #{name} already exists"
  113 +
  114 + # Create new node and push it as a group child.
  115 + @nodes.push(test = new Test(name, @, @_type, raw))
  116 + return test
43 117
44 118
45 119 #
@@ -47,7 +121,6 @@ return class Group extends Node
47 121 # is found.
48 122 #
49 123 # @param name {String} simple node name.
50   - #
51 124 # @return {Node}
52 125 #
53 126 get: (name) ->
@@ -84,3 +157,19 @@ return class Group extends Node
84 157 #
85 158 get_child_prefix: ->
86 159 return if @name is '' then @name else @name + '.'
  160 +
  161 +
  162 + #
  163 + # Returns root of the node selection tree. If the node is a group,
  164 + # it will use its root to attach child nodes selection trees by
  165 + # their simple names.
  166 + #
  167 + # @return {->} node selection tree root.
  168 + #
  169 + get_selection_tree: ->
  170 +
  171 + # Assign fully qualified node name.
  172 + name = if @name then @_type + '.' + @name else @_type
  173 +
  174 + # Assign the selection function.
  175 + return @_selection ?= -> context().select(name)
53 source/node.coffee
@@ -11,26 +11,17 @@ return class Node
11 11 #
12 12 # @param name {String} node full name.
13 13 # @param parent {Node} node parent.
  14 + # @param type {String} node type name.
14 15 # @param raw {Object} node definition.
15 16 #
16 17 constructor: (@name, @parent, @_type, raw) ->
17 18
18   - # Node simple name.
  19 + # Node simple name.
19 20 @_simple = @name.substr(@parent.get_child_prefix().length)
20 21
21   - # Assert the simple name is selectable.
22   - if not @_is_selectable(@_simple)
23   - throw new Error "Simple name '#{@_simple}' is not selectable"
24   -
25   - # Node display name.
26   - @_display = raw.display || @name
27   -
28 22 # Collection of preloaded modules.
29 23 @_envs = raw.envs || []
30 24
31   - # Collection of node dependences (in qa).
32   - @_dpds = raw.dependences || []
33   -
34 25 # Minimal number of times to run (in pfc).
35 26 @_min_arg = raw.min_arg || 0
36 27
@@ -47,46 +38,6 @@ return class Node
47 38 @_after_each = raw.after_each || (->)
48 39
49 40
50   - #
51   - # Returns true if the given name matches variable regexp
52   - # and therefore is selectable.
53   - #
54   - # @param name {String}
55   - # @return {Boolean}
56   - #
57   - _is_selectable: (name) ->
58   - return regexp().VARIABLE.test(name)
59   -
60   -
61   - #
62   - # Returns the node simple name. Simple name is assured to be
63   - # selectable, that means the client will be able to treat it as
64   - # a normal property when selecting the tests via selection tree.
65   - #
66   - # @return {String}
67   - #
68   - get_simple_name: ->
69   - return @_simple
70   -
71   -
72   - #
73   - # Returns root of the node selection tree. If the node is a group,
74   - # it will use its root to attach child nodes selection trees by
75   - # their simple names.
76   - #
77   - # @return {->} node selection tree root.
78   - #
79   - get_selection_tree: ->
80   -
81   - # Assign fully qualified node name.
82   - name = if @name then @_type + '.' + @name else @_type
83   -
84   - # Assign the selection function.
85   - return @_selection ?= ->
86   - context().select(name)
87   -
88   -
89   -
90 41 # draft
91 42 preload_envs: ->
92 43 F.run(env) for env in @_envs
12 source/runner.coffee
... ... @@ -0,0 +1,12 @@
  1 +return class Runner
  2 +
  3 + run: (tests) ->
  4 +
  5 + _run_loop: ->
  6 +
  7 +
  8 +# Run uruchamia podstawowe testy - musi najpierw zbudowac tablice swoich test-cases: to musi byc tak zrobione, aby np mogl latwo wsadzic testy, ktore wykonuja measure!
  9 +#
  10 +# Jak chce takie test-cases zbudowac? O ile dla powtarzanych testow moge powtorzyc instancje testu, o tyle nie wiem jak measure tam wsadzic :/
  11 +#
  12 +# Musze trzymac informacje o aktualnym tescie D:
4 source/test.coffee
@@ -17,6 +17,10 @@ return class Test extends Node
17 17 if not F.is_function(@_run)
18 18 throw new Error "Run method not found: #{@name}"
19 19
  20 + # Assert the simple name does not contain dot character.
  21 + if @_simple.indexOf('.') isnt -1
  22 + throw new Error "Simple name '#{@_simple}' contains dot character."
  23 +
20 24
21 25 #
22 26 # Stub method that returns the node as its tests. Exists in order to
53 source/type.coffee
... ... @@ -1,6 +1,5 @@
1 1 #
2 2 # @require:
3   -# Test: fest/test
4 3 # Group: fest/group
5 4 #
6 5
@@ -15,7 +14,7 @@ return class Type
15 14 constructor: (@name, @runner) ->
16 15
17 16 # Root group of the groups hierarchy tree.
18   - @_root = new Group('')
  17 + @_root = new Group('', undefined, @name)
19 18
20 19 # Last referenced group. Default parent when adding test cases.
21 20 @_last_group = @_root
@@ -29,40 +28,32 @@ return class Type
29 28
30 29
31 30 #
32   - # Registers a group under the given name.
  31 + # Registers a scenario group under the given name.
33 32 #
34 33 # @param name {String} group name.
35 34 # @param raw {Object} group definition.
36 35 #
37   - group: (name, raw) ->
38   -
39   - # From the group name: if it's absolute & its full name.
40   - absolute = @_is_group_absolute(name)
41   - full_name = @_resolve_group_name(name, absolute)
42   -
43   - # Retrieve the group parent & create the group inside.
44   - parent = @get(full_name, true)
45   - group = parent.add(Group, full_name, @name, raw)
46   -
47   - # Set group as the last group & as node group if it's absolute.
48   - @_last_group = group
49   - @_node_group = group if absolute
  36 + scenario: (name, raw = {}) ->
  37 + raw.scenario = true
  38 + @group(name, raw)
50 39
51 40
52 41 #
53   - # References a group with the given name.
  42 + # Registers a group under the given name.
54 43 #
55 44 # @param name {String} group name.
  45 + # @param raw {Object} group definition.
56 46 #
57   - use: (name) ->
  47 + group: (name, raw) ->
58 48
59 49 # From the group name: if it's absolute & its full name.
60 50 absolute = @_is_group_absolute(name)
61 51 full_name = @_resolve_group_name(name, absolute)
62 52
63   - # Retrieves the group matching the given full_name.
64   - group = @get(full_name, false)
65   -
  53 + # Retrieve the group parent & create the group inside.
  54 + parent = @get(full_name, true)
  55 + group = parent.register_group(full_name, raw)
  56 +
66 57 # Set group as the last group & as node group if it's absolute.
67 58 @_last_group = group
68 59 @_node_group = group if absolute
@@ -99,26 +90,6 @@ return class Type
99 90
100 91
101 92 #
102   - # Registers a test under the latest referenced group.
103   - #
104   - # @param name {String} test name.
105   - # @param raw {Object} test definition.
106   - #
107   - test: (name, raw) ->
108   - @_last_group.add(Test, @_resolve_test_name(name), @name, raw)
109   -
110   -
111   - #
112   - # Returns full name from the given test name. The test is always a
113   - # child of the last referenced group.
114   - #
115   - # @param name {String} test name.
116   - #
117   - _resolve_test_name: (name) ->
118   - return @_last_group.get_child_prefix() + name
119   -
120   -
121   - #
122 93 # Returns the node corresponding to the given name. Returns parent
123 94 # of that node if parent parameter was set to true.
124 95 #

0 comments on commit 1939d51

Please sign in to comment.
Something went wrong with that request. Please try again.