package pfff

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

Source file unit_linter.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
open Common
open OUnit

module E = Error_code

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

(*****************************************************************************)
(* Unit tests *)
(*****************************************************************************)

let unittest ~ast_of_file =
 "linter" >::: [
  "basic checkers" >:: (fun () ->
  let p path = 
     Filename.concat Config_pfff.path 
            (Filename.concat "tests/GENERIC/scheck" path )
  in

  let test_files = [
    p "foo.py";

    p "cfg.py";

(*
    p "builtins.php";
    p "common.php";

    p "includes.php";

    p "variables.php";
    p "variables_fp.php";
    p "arrays.php";
    p "foreach.php";
    p "edit_distance.php";

    p "functions.php";
    p "static_methods.php";
    p "methods.php";

    p "classes.php";
    p "traits.php";
(*
    p "namespaces.php";
    p "namespaces_uses.php";
*)

    p "references.php";
    p "xhp.php";
    p "typing.php";

    p "dynamic_bailout.php";

    p "format_string.php";
    p "ternary_if.php";
    p "misc.php";

    p "lint.php";
    p "micro_clones.php";
*)
  ] 
  in

  (* expected *)
  let expected_error_lines = E.expected_error_lines_of_files test_files in

  (* actual *)
  E.g_errors := [];
  let verbose = false in
  (* really old:
   *  let db = Database_php_build.db_of_files_or_dirs files in
   *  let find_entity = Some (Database_php_build.build_entity_finder db) in
   *
   * old:
   *  let _files_for_codegraph = test_files in
   *  let (cg, _stat) = Graph_code_php.build ~verbose "/" files in
   *  let find_entity = 
   *   Some (Entity_php.entity_finder_of_graph_code ~check_dupes:true
             cg "/") in
   * let env = Env_php.mk_env ~php_root:"/" in
   *)
  let find_entity = None in
  (* run the bugs finders *)
  test_files |> List.iter (fun file ->
    let ast = ast_of_file file in
    Check_all_generic.check_file ~verbose ~find_entity ast;
  );

  (* compare *)
  let actual_errors = !E.g_errors in
  if verbose 
  then actual_errors |> List.iter (fun e -> pr (E.string_of_error e));
  E.compare_actual_to_expected actual_errors expected_error_lines
  )]
OCaml

Innovation. Community. Security.