Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
probe() { echo 111; }
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int probe(void) { return 111; }
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/c_sharp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Box { int probe() { return 111; } }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(defn probe [x] (+ x 111))
10 changes: 10 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/clojure_forms.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(defn- private-probe [x]
(+ x 111))
(defmacro macro-probe [x]
`(+ ~x 111))
(require '[clojure.test :refer [deftest is]])
(deftest test-probe
(is (= 111 111)))
(defmulti method-probe identity)
(defmethod method-probe :default [x]
(+ x 111))
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/cmake.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function(probe)
message(STATUS "111")
endfunction()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
macro(probe)
message(STATUS "111")
endmacro()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(defun probe (x)
(+ x 111))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(defmacro macro-probe (x)
`(+ ,x 111))
(defgeneric generic-probe (x)
(:documentation "111"))
(defmethod method-probe ((x integer))
(+ x 111))
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int probe() { return 111; }
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/crystal.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def probe(x)
x + 111
end
2 changes: 2 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/css.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:root { --value: 111; }
p { width: calc(var(--value) * 1px); }
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int probe(int x) { return x + 111; }
5 changes: 5 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/elixir.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Box do
def probe(x) do
x + 111
end
end
14 changes: 14 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/elixir_forms.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Box do
defp private_probe(x) do
x + 111
end
defmacro macro_probe(x) do
111
end
defmacrop private_macro(x) do
111
end
def zero_probe do
111
end
end
14 changes: 14 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/elixir_guarded.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Box do
def guarded(x) when is_integer(x) do
111
end
defp private_guarded(x) when is_integer(x) do
111
end
defmacro macro_guarded(x) when is_integer(x) do
111
end
defmacrop private_macro_guarded(x) when is_integer(x) do
111
end
end
4 changes: 4 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/elm.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Probe exposing (probe)

probe x =
x + 111
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/fish.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function probe
echo 111
end
4 changes: 4 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/fortran.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function probe(x) result(y)
integer :: x, y
y = x + 111
end function probe
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
program probe
print *, 111
end program probe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
subroutine probe(x)
integer :: x
x = x + 111
end subroutine probe
2 changes: 2 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/go.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package probe
func probe() int { return 111 }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{define "probe"}}111{{end}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query probe {
user { field111 }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
field111
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fragment probe on User {
field111
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def probe(x) { return x + 111 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Box {
def probe(x) {
return x + 111
}
}
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/haskell.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
probe x = x + 111
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/java.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Box { int probe() { return 111; } }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function probe(x) { return x + 111; }
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/kotlin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fun probe(x: Int): Int = x + 111
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/latex.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\newcommand{\probe}[1]{#1 + 111}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\DeclarePairedDelimiter{\probe}{111}{x}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\newenvironment{probe}{111}{}
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/latex_old.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\def\probe{
111
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\newtheorem{probe}{Probe111}
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/lua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function probe(x)
return x + 111
end
2 changes: 2 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/make.makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
probe:
@echo 111
2 changes: 2 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/nim.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proc probe(x: int): int =
x + 111
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/perl.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sub probe { return 111; }
2 changes: 2 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
function probe($x) { return $x + 111; }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function probe { return 111 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Box {
[int] probe() {
return 111
}
}
8 changes: 8 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/proto.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";
service Box {
rpc probe (Input) returns (Output) {
option (note) = "111";
}
}
message Input {}
message Output {}
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/prql.prql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let probe x -> x + 111
2 changes: 2 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def probe(x):
return x + 111
6 changes: 6 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/r.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
probe <- function(x) {
if (x > 0) {
return(111)
}
return(x)
}
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/r_anonymous.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lapply(c(1), function(x) {
x + 111
})
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/r_equal.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
probe = function(x) {
x + 111
}
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/r_right.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function(x) {
x + 111
}) -> probe
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
probe <<- function(x) {
x + 111
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function(x) {
x + 111
}) ->> probe
2 changes: 2 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/rego.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package example
probe(x) = y { y := x + 111 }
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def probe(x)
x + 111
end
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/rust.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn probe(x: i32) -> i32 { x + 111 }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def probe(x: Int): Int = x + 111
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/sql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE FUNCTION probe(x integer) RETURNS integer LANGUAGE SQL AS $$ SELECT x + 111 $$;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
func probe(_ x: Int) -> Int { return x + 111 }
3 changes: 3 additions & 0 deletions bins/codefang/tests/fixtures/shotness_languages/tcl.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
proc probe {x} {
return 111
}
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/tsx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function probe(x: number): number { return x + 111; }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function probe(x: number): number { return x + 111; }
1 change: 1 addition & 0 deletions bins/codefang/tests/fixtures/shotness_languages/zig.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn probe(x: i32) i32 { return x + 111; }
123 changes: 123 additions & 0 deletions bins/codefang/tests/shotness_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,129 @@ fn commit(repo: &TestRepo, day: i64, files: &[(&str, &[u8])]) {
commit_files(repo, &format!("day {day}"), T0 + day * DAY, files).expect("commit");
}

// BUG: specs/bugs/BUG-kotlin-shotness-empty.md
#[test]
fn kotlin_shotness_with_limit_and_text_reports_functions() {
let repo = init_repo().expect("init");
commit(
&repo,
0,
&[("Calculator.kt", b"fun sum(a: Int, b: Int): Int = a + b\n")],
);
let text = stdout_ok(&[
"-a",
SHOTNESS,
"--limit",
"200",
"--format",
"text",
path(&repo),
]);
assert!(text.contains("1 nodes"), "{text}");
assert!(text.contains("sum"), "{text}");
}

#[test]
fn kotlin_shotness_qualifies_class_methods() {
let repo = init_repo().expect("init");
commit(
&repo,
0,
&[(
"Calculator.kt",
b"class Calculator { fun sum(a: Int, b: Int): Int = a + b }\n",
)],
);
assert_eq!(
entities(&shotness(&repo, &[])),
vec![(
"Calculator.sum".into(),
"Function".into(),
"Calculator.kt".into()
)]
);
}

#[test]
fn kotlin_shotness_qualifies_object_methods() {
let repo = init_repo().expect("init");
commit(
&repo,
0,
&[("Service.kt", b"object Service { fun work() = 1 }\n")],
);
assert_eq!(
entities(&shotness(&repo, &[])),
vec![(
"Service.work".into(),
"Function".into(),
"Service.kt".into()
)]
);
}

#[test]
fn kotlin_shotness_qualifies_implicit_companion_methods() {
let repo = init_repo().expect("init");
commit(
&repo,
0,
&[(
"Service.kt",
b"class Service {\ncompanion object {\nfun work() = 1\n}\n}\n",
)],
);
assert_eq!(
entities(&shotness(&repo, &[])),
vec![(
"Service.Companion.work".into(),
"Function".into(),
"Service.kt".into()
)]
);
}

#[test]
fn kotlin_shotness_qualifies_named_companion_methods() {
let repo = init_repo().expect("init");
commit(
&repo,
0,
&[(
"Service.kt",
b"class Service {\ncompanion object Factory {\nfun work() = 1\n}\n}\n",
)],
);
assert_eq!(
entities(&shotness(&repo, &[])),
vec![(
"Service.Factory.work".into(),
"Function".into(),
"Service.kt".into()
)]
);
}

#[test]
fn kotlin_script_shotness_counts_body_changes_and_couplings() {
let repo = init_repo().expect("init");
commit(
&repo,
0,
&[("script.kts", b"fun first() = 1\nfun second() = 2\n")],
);
commit(
&repo,
1,
&[("script.kts", b"fun first() = 10\nfun second() = 2\n")],
);
let report = shotness(&repo, &["--limit", "200"]);
assert_eq!(total_nodes(&report), 2);
assert_eq!(change_count(&report, "first", "script.kts"), 2);
assert_eq!(change_count(&report, "second", "script.kts"), 1);
assert_eq!(co_changes(&report, "first", "second"), 1);
}

/// `(name, type, file)` of every entity in the report, key-sorted.
fn entities(report: &Value) -> Vec<(String, String, String)> {
let mut out: Vec<(String, String, String)> = report["node_hotness"]
Expand Down
Loading
Loading