Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added test framework - see test_cluster_chart.e for example of test file

  • Loading branch information...
commit 90d69dd0ab8f36e9fe6f6df61c37c3946e264515 1 parent f4372f4
tdidriksen authored
4 src/type_checker/tbon_tc_error.e
@@ -21,7 +21,9 @@ feature -- Initialization
21 21 -- Initialize `Current'.
22 22 do
23 23 code := an_error_code
24   - message := an_error_message.string
  24 + if an_error_message /= Void then
  25 + message := an_error_message.string
  26 + end
25 27 end
26 28
27 29 feature -- Access
6 src/type_checker/tbon_tc_warning.e
@@ -17,11 +17,13 @@ create
17 17 make
18 18
19 19 feature -- Initialization
20   - make (an_error_code: INTEGER; an_error_message: STRING)
  20 + make (an_error_code: INTEGER; a_warning_message: STRING)
21 21 -- Initialize `Current'.
22 22 do
23 23 code := an_error_code
24   - message := an_error_message.string
  24 + if a_warning_message /= Void then
  25 + message := a_warning_message.string
  26 + end
25 27 end
26 28
27 29 feature -- Access
37 test/type_checker/TESTGEN/type_checker_test.e
... ... @@ -1,37 +0,0 @@
1   -note
2   -
3   - description: "Test harness root class"
4   - generator: "getest version 3.9"
5   -
6   -class TYPE_CHECKER_TEST
7   -
8   -inherit
9   -
10   - TS_TESTER
11   - redefine
12   - build_suite
13   - end
14   -
15   -create
16   -
17   - make, make_default
18   -
19   -feature -- Element change
20   -
21   - build_suite
22   - -- Add to `suite' the test cases that need to executed.
23   - local
24   - l_regexp: like enabled_test_cases
25   - l_name: STRING
26   - l_test1: TEST_CLUSTER_CHART
27   - do
28   - l_regexp := enabled_test_cases
29   - l_name := "TEST_CLUSTER_CHART.test_true"
30   - if l_regexp = Void or else l_regexp.recognizes (l_name) then
31   - create l_test1.make_default
32   - l_test1.set_test (l_name, agent l_test1.test_true)
33   - put_test (l_test1)
34   - end
35   - end
36   -
37   -end
0  test/type_checker/class_chart.bon → test/type_checker/bon/class_chart.bon
File renamed without changes
42 test/type_checker/bon/cluster_does_not_exist.bon
... ... @@ -0,0 +1,42 @@
  1 +system_chart THE_WORLD
  2 + cluster EARTH description "A small, insignificant planet."
  3 +end
  4 +
  5 +class_chart CITIZEN
  6 +indexing
  7 + clauster: "CIVIL_STATUS " ;
  8 + created: "1993-03-15 jmn";
  9 + revised: "1993-05-12 kw"
  10 +explanation
  11 + "Person born or living in a country"
  12 +part "1/1 "
  13 +query
  14 + "Name", "Sex", "Age", "Single", "Spouse", "Children", "Parents",
  15 + "Impediment to marriage"
  16 +command
  17 + "Marry", "Divorce"
  18 +constraint
  19 + "Each citizen has two parents.",
  20 + "At most one spouse allowed.",
  21 + "May not marry children or parents or person of same sex.",
  22 + "Spouse's spouse must be this person.",
  23 + "All children, if any, must have this person among their parents."
  24 +end
  25 +
  26 +class_chart NOBLEPERSON
  27 +indexing
  28 + cluaster: "CIVIL_STATUS" ;
  29 + created: "1993-03-15 jmn";
  30 + revised: "1993-05-12 kw", "1993-12-10 kw"
  31 +explanation
  32 + "Person of noble rank"
  33 +part "1/1 "
  34 +inherit CITIZEN
  35 +query
  36 + "Assets", "Butler"
  37 +constraint
  38 + "Enough property for independence.",
  39 + "Can only marry other noble person.",
  40 + "Wedding celebrated with style.",
  41 + "Married nobility share their assets and must have a butler."
  42 +end
72 test/type_checker/tbon_tc_test.e
... ... @@ -0,0 +1,72 @@
  1 +note
  2 + description: "Shared items for all type checker test classes."
  3 + author: ""
  4 + date: "$Date$"
  5 + revision: "$Revision$"
  6 +
  7 +class
  8 + TBON_TC_TEST
  9 +
  10 +inherit
  11 + TBON_TC_ERROR
  12 +
  13 +feature -- Access
  14 + parser: BON_PARSER
  15 +
  16 + type_checker: TEXTUAL_BON_TYPE_CHECKER
  17 +
  18 +feature -- Setup
  19 + set_up
  20 + -- Do this before _first_ test.
  21 + do
  22 + create parser.make_parser
  23 + end
  24 +
  25 + bon_specification_from_file (a_filename: STRING): BON_SPECIFICATION
  26 + -- Get a BON specification from `a_filename'.
  27 + local
  28 + a_file: KL_TEXT_INPUT_FILE
  29 + filename: STRING
  30 + do
  31 + filename := a_filename.string
  32 + if prepend_exec_path then
  33 + filename.prepend_string (exec_path)
  34 + end
  35 + create a_file.make (filename)
  36 + a_file.open_read
  37 + if a_file.is_open_read then
  38 + parser.reset_scanner
  39 + parser.set_input_buffer (parser.new_file_buffer (a_file))
  40 + parser.parse
  41 + a_file.close
  42 + else
  43 + io.set_error_default
  44 + io.put_string ("bon_parser: cannot read %'")
  45 + io.put_string (filename)
  46 + io.put_string ("%'%N")
  47 + end
  48 + Result := parser.bon_specification
  49 + end
  50 +
  51 + set_up_test
  52 + -- Do this before _every_ test.
  53 + do
  54 + create type_checker.make
  55 + end
  56 +
  57 +feature -- Constants
  58 +
  59 + prepend_exec_path: BOOLEAN = True
  60 + -- Should th exec_path be prepended to the path?
  61 +
  62 + exec_path: STRING = "../../../bon/"
  63 + -- Path to BON files from executable library.
  64 +
  65 +feature -- Status report
  66 +
  67 + error_occurred (an_error_code: INTEGER): BOOLEAN
  68 + do
  69 + Result := type_checker.errors.has (create {TBON_TC_ERROR}.make (an_error_code, Void))
  70 + end
  71 +
  72 +end
56 test/type_checker/test_cluster_chart.e
... ... @@ -1,5 +1,5 @@
1 1 note
2   - description: "Tests for cluster charts"
  2 + description: "Tests for cluster charts."
3 3 author: ""
4 4 date: "$Date$"
5 5 revision: "$Revision$"
@@ -9,58 +9,36 @@ class
9 9
10 10 inherit
11 11 TS_TEST_CASE
12   - redefine
  12 + undefine
13 13 set_up
14 14 end
15 15
  16 + TBON_TC_TEST
  17 + undefine
  18 + is_equal
  19 + end
  20 +
16 21 create
17 22 make_default
18 23
19   -feature -- Access
20   - parser: BON_PARSER
21   -
22   - type_checker: TEXTUAL_BON_TYPE_CHECKER
23   -
24   -feature -- Setup
25   - set_up
26   - do
27   - create parser.make_parser
28   - end
29   -
30   - bon_specification_from_file (a_filename: STRING): BON_SPECIFICATION
31   - -- Get a BON specification from `a_filename'
  24 +feature -- Test
  25 + test_cluster_does_not_exist
32 26 local
33   - a_file: KL_TEXT_INPUT_FILE
34   - do
35   - create a_file.make (a_filename)
36   - a_file.open_read
37   - if a_file.is_open_read then
38   - parser.reset_scanner
39   - parser.set_input_buffer (parser.new_file_buffer (a_file))
40   - parser.parse
41   - a_file.close
42   - else
43   - io.set_error_default
44   - io.put_string ("bon_parser: cannot read %'")
45   - io.put_string (a_filename)
46   - io.put_string ("%'%N")
47   - end
48   - Result := parser.bon_specification
49   - end
50   -
51   - set_up_test
  27 + bon_spec: BON_SPECIFICATION
52 28 do
53   - create type_checker.make
  29 + set_up_test
  30 + bon_spec := bon_specification_from_file ("cluster_does_not_exist.bon")
  31 + assert_false ("Type checking failed", type_checker.check_bon_specification (bon_spec))
  32 + assert ("Cluster does not exist error occurred", error_occurred (err_code_cluster_does_not_exist))
54 33 end
55 34
56   -feature -- Test
57   - test_true
  35 + test_success
58 36 local
59 37 bon_spec: BON_SPECIFICATION
60 38 do
61 39 set_up_test
62   - bon_spec := bon_specification_from_file ("../../../class_chart.bon")
63   - assert ("Bon spec succeeds", type_checker.check_bon_specification (bon_spec))
  40 + bon_spec := bon_specification_from_file ("class_chart.bon")
  41 + assert ("Bon spec succeeded", type_checker.check_bon_specification (bon_spec))
64 42 end
65 43
66 44 end
4 test/type_checker/type_checker_test.ecf
@@ -12,7 +12,7 @@
12 12 </option>
13 13 <precompile name="base_pre" location="$ISE_PRECOMP\base.ecf"/>
14 14 <library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
15   - <library name="base2" location="\Users\Thomas\Documents\ITU\6. semester\Bachelor\EiffelBase2\base2.ecf"/>
  15 + <library name="base2" location="$EIFFEL_BASE_2\base2.ecf"/>
16 16 <library name="gobo_kernel" location="$ISE_LIBRARY\library\gobo\gobo_kernel.ecf"/>
17 17 <library name="gobo_lexical" location="$ISE_LIBRARY\library\gobo\gobo_lexical.ecf"/>
18 18 <library name="gobo_parse" location="$ISE_LIBRARY\library\gobo\gobo_parse.ecf"/>
@@ -20,7 +20,7 @@
20 20 <library name="gobo_test" location="$ISE_LIBRARY\library\gobo\gobo_test.ecf"/>
21 21 <library name="gobo_utility" location="$ISE_LIBRARY\library\gobo\gobo_utility.ecf"/>
22 22 <cluster name="parser" location="$REBON\src\parser\"/>
23   - <cluster name="scanner" location="\Users\Thomas\Documents\ITU\6. semester\Bachelor\rEBON\src\scanner\"/>
  23 + <cluster name="scanner" location="$REBON\src\scanner\"/>
24 24 <cluster name="type_checker" location="$REBON\src\type_checker\" recursive="true"/>
25 25 <cluster name="type_checker_test" location=".\" recursive="true">
26 26 <cluster name="mog" location="$REBON\library\mog\" recursive="true"/>

0 comments on commit 90d69dd

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