package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file unit_parsing_cpp.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
open Common
open OUnit

module Flag = Flag_parsing

(*****************************************************************************)
(* Helpers *)
(*****************************************************************************)
let parse file = 
  Common.save_excursion Flag.error_recovery false (fun () ->
  Common.save_excursion Flag.show_parsing_error false (fun () ->
  Common.save_excursion Flag.verbose_parsing false (fun () ->
    Parse_cpp.parse file
  )))
(*****************************************************************************)
(* Unit tests *)
(*****************************************************************************)

let unittest =
 "parsing_cpp" >::: [

   (*-----------------------------------------------------------------------*)
   (* Lexing *)
   (*-----------------------------------------------------------------------*)
   (* todo: 
    * - make sure parse int correctly, and float, and that actually does
    *   not return multiple tokens for 42.42
    * - ...
    *)

   (*-----------------------------------------------------------------------*)
   (* Parsing *)
   (*-----------------------------------------------------------------------*)
   "regression files" >:: (fun () ->
     let dir = Filename.concat Config_pfff.path "/tests/cpp/parsing" in
     let files = 
       Common2.glob (spf "%s/*.cpp" dir) @ Common2.glob (spf "%s/*.h" dir) in
     files +> List.iter (fun file ->
       try
         let _ast = parse file in
         ()
       with Parse_cpp.Parse_error _ ->
         assert_failure (spf "it should correctly parse %s" file)
     )
   );
   
   "rejecting bad code" >:: (fun () ->
     let dir = Filename.concat Config_pfff.path "/tests/cpp/parsing_errors" in
     let files = Common2.glob (spf "%s/*.cpp" dir) in
     files +> List.iter (fun file ->
       try 
         let _ast = parse file in
         assert_failure (spf "it should have thrown a Parse_error %s" file)
       with
       | Parse_cpp.Parse_error _ -> ()
       | exn -> assert_failure (spf "throwing wrong exn %s on %s"
                                   (Common.exn_to_s exn) file)
     )
   );
   
 (* parsing C files (and not C++ files) possibly containing C++ keywords *)
   "C regression files" >:: (fun () ->
     let dir = Filename.concat Config_pfff.path "/tests/c/parsing" in
     let files = 
       Common2.glob (spf "%s/*.c" dir)
       (* @ Common2.glob (spf "%s/*.h" dir) *) in
     files +> List.iter (fun file ->
       try
         let _ast = parse file in
         ()
       with Parse_cpp.Parse_error _ ->
         assert_failure (spf "it should correctly parse %s" file)
     )
   );

 (*-----------------------------------------------------------------------*)
 (* Misc *)
 (*-----------------------------------------------------------------------*)
 ]
OCaml

Innovation. Community. Security.