Skip to content

Commit

Permalink
Unused declarations: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kakadu <[email protected]>
  • Loading branch information
Kakadu committed Jul 24, 2024
1 parent 8b10e24 commit 177ae8d
Show file tree
Hide file tree
Showing 25 changed files with 187 additions and 15 deletions.
6 changes: 6 additions & 0 deletions tests/unused_func/Inline_tests.t/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_build
_coverage
/_esy
/node_modules
/esy.lock
/.melange.eobjs
4 changes: 4 additions & 0 deletions tests/unused_func/Inline_tests.t/.ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
profile=janestreet
sequence-style=terminator
max-indent=2

35 changes: 35 additions & 0 deletions tests/unused_func/Inline_tests.t/CSharpOOP.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1"
synopsis: "FIXME An interpreter for language"
description:
"FIXME. A longer description, for example, which are the most interesing features being supported, etc."
maintainer: ["Julia Kononova"]
authors: ["Julia Kononova"]
license: "LGPL-3.0-or-later"
homepage: "FIXME Homepage"
bug-reports: "FIXME where to put bug reports about the code"
depends: [
"dune" {>= "3.7"}
"angstrom"
"ppx_inline_test" {with-test}
"ppx_expect"
"ppx_deriving"
"bisect_ppx"
"odoc" {with-doc}
"ocamlformat" {build}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
1 change: 1 addition & 0 deletions tests/unused_func/Inline_tests.t/Nonwrapped.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let rec nonwrapped_fac n = if n <= 1 then 1 else n * nonwrapped_fac (n - 1)
3 changes: 3 additions & 0 deletions tests/unused_func/Inline_tests.t/Nonwrapped.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(* If we don't create .mli, the linter will not warn about this factorial.
Don't know yet, is it good or bad *)
val nonwrapped_fac : int -> int
3 changes: 3 additions & 0 deletions tests/unused_func/Inline_tests.t/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a homework for functional programming course.

Author: [Julia Kononova](https://github.com/juliakononov)
12 changes: 12 additions & 0 deletions tests/unused_func/Inline_tests.t/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(env
(dev
(flags
(:standard -warn-error -A -w -3-9-32-34-58 -w -37-69)))
(release
(flags
(:standard -warn-error -A -w -58))))

(library
(name nonwrapped_lib)
(modules Nonwrapped)
(wrapped false))
18 changes: 18 additions & 0 deletions tests/unused_func/Inline_tests.t/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(lang dune 3.7)

(cram enable)

(license LGPL-3.0-or-later)

(package
(name CSharpOOP) ; FIXME and regenerate .opam file using 'dune build @install'
(allow_empty)
(synopsis "xxx")
(description "xxx")
(version 0.1)
(depends
dune
angstrom
(ppx_inline_test :with-test)
ppx_expect
ppx_deriving))
1 change: 1 addition & 0 deletions tests/unused_func/Inline_tests.t/lib/ast.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type statement = Return of int option [@@deriving show { with_path = false }]
15 changes: 15 additions & 0 deletions tests/unused_func/Inline_tests.t/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(library
(name wrapped_lib)
(modules Ast Parser)
(wrapped true)
(libraries angstrom)
(preprocess
(pps ppx_deriving.show)))

(library
(name tests)
(modules p_tests)
(libraries wrapped_lib nonwrapped_lib)
(inline_tests)
(preprocess
(pps ppx_expect ppx_inline_test)))
19 changes: 19 additions & 0 deletions tests/unused_func/Inline_tests.t/lib/p_tests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
open Wrapped_lib.Parser
open Wrapped_lib.Ast

(* PARSERS *)
let show_wrap form = function
| Some x -> form Format.std_formatter x
| _ -> print_endline "Parsing error"
;;

let print_pars ps pp str = show_wrap pp (parse_to_some ps str)

(* statements tests*)

let test_decl = print_pars s_declaration pp_statement

let%expect_test _ =
print_endline "Hello, world!";
[%expect "Hello, world!"]
;;
6 changes: 6 additions & 0 deletions tests/unused_func/Inline_tests.t/lib/p_tests.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(** Copyright 2023-2024, Julia Kononova *)

(** SPDX-License-Identifier: LGPL-3.0-or-later *)

(* val show_wrap : (Format.formatter -> 'a -> unit) -> 'a option -> unit
val print_pars : 'a Angstrom.t -> (Format.formatter -> 'a -> unit) -> string -> unit *)
7 changes: 7 additions & 0 deletions tests/unused_func/Inline_tests.t/lib/parser.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let parse_to_some p str =
match Angstrom.parse_string p ~consume:Angstrom.Consume.All str with
| Ok x -> Some x
| Error _ -> None
;;

let s_declaration = Angstrom.return (Ast.Return None)
2 changes: 2 additions & 0 deletions tests/unused_func/Inline_tests.t/lib/parser.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val parse_to_some : 'a Angstrom.t -> string -> 'a option
val s_declaration : Ast.statement Angstrom.t
7 changes: 7 additions & 0 deletions tests/unused_func/Inline_tests.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$ dune build
$ dune test
$ dune describe

$ zanuda -unused-decls . |grep -v "Base\|Angstrom\|Ppx_deriving_runtime"
Unused declarations:
0: Nonwrapped.nonwrapped_fac
5 changes: 5 additions & 0 deletions tests/unused_func/Simple.t/SecondTU.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
let first = let open Simple in meow;;
let second = let open Simple in Meow.InnerMeow.inner;;

let%test _ = Simple.is_space ' '
(* let%expect_test _ =
Printf.printf "%b\n" (Simple.is_space ' ');
[%expect "true"] *)
7 changes: 5 additions & 2 deletions tests/unused_func/Simple.t/Simple.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
let meow = 1;;

module Meow = struct
module InnerMeow = struct
let inner = 7
module InnerMeow = struct
let inner = 7
end
let woof = 3
let meow = 11
end

let _false_use = Meow.woof


let is_space = function ' '| '\n' -> true | _ -> false
3 changes: 2 additions & 1 deletion tests/unused_func/Simple.t/Simple.mli
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Meow : sig
module InnerMeow : sig
module InnerMeow : sig
val inner : int
end
val woof : int
val meow : int
end

val meow : int
val is_space : char -> bool
1 change: 1 addition & 0 deletions tests/unused_func/Simple.t/custom_demo.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_int (Custom_lib.Custom_lib_impl.incr 41)
1 change: 1 addition & 0 deletions tests/unused_func/Simple.t/custom_lib_impl.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let incr n = n+1
1 change: 1 addition & 0 deletions tests/unused_func/Simple.t/custom_lib_impl.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val incr : int -> int
27 changes: 19 additions & 8 deletions tests/unused_func/Simple.t/dune
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
(library
(name test_Simple)
(wrapped false)
(modules
Simple
SecondTU
)
; (flags
; (:standard -dtypedtree))
(instrumentation
(backend bisect_ppx)))
(modules
Simple
SecondTU
;
)
(inline_tests)
(preprocess
(pps ppx_expect ppx_inline_test)))

(library
(name custom_lib)
(public_name Simple.Custom)
;(package Simple)
(modules custom_lib_impl))

(executable
(name custom_demo)
(modules custom_demo)
(libraries custom_lib))
3 changes: 3 additions & 0 deletions tests/unused_func/Simple.t/dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
(lang dune 2.8)

(cram enable)

(package
(name Simple))
13 changes: 9 additions & 4 deletions tests/unused_func/Simple.t/run.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
$ dune build
$ zanuda -unused-decls .
unused decl: Simple.Meow.meow
unused decl: Simple.Meow.woof
$ dune build @check
$ dune describe
$ zanuda -unused-decls .
module "Custom_lib" is omitted
Unused declarations:
0: Custom_lib_impl.incr
1: Simple.Meow.meow
2: Simple.Meow.woof
# Custom_lib_impl.incr is not found because a custom public name for library 'custom_lib'
2 changes: 2 additions & 0 deletions tests/unused_func/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(cram
(deps %{bin:zanuda}))

0 comments on commit 177ae8d

Please sign in to comment.