Skip to content

Commit

Permalink
Add snapshot testing for statement parsing
Browse files Browse the repository at this point in the history
For statements it is hard to write any unit tests, as a statement is a rather complex struct also containing some meta information. It is much easier to test the statement parsing, looking at the generated statement and review it instead.
  • Loading branch information
Kraemii committed Nov 25, 2024
1 parent bd6bfde commit eb7fa2c
Show file tree
Hide file tree
Showing 32 changed files with 428 additions and 18 deletions.
62 changes: 62 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 28 additions & 13 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ license = "GPL-2.0-or-later"

[dependencies]
aes = "0.8.2"
aes-gcm = { version = "0.10.1"}
aes-gcm = { version = "0.10.1" }
anyhow = "1.0.75"
async-trait = "0.1.68"
base64 = "0.21.2"
cbc = { version = "0.1.2", features = ["alloc"]}
cbc = { version = "0.1.2", features = ["alloc"] }
ccm = "0.5.0"
chacha20 = "0.9.1"
chrono = { version = "0.4.23", default-features = false, features = ["clock"]}
chrono = { version = "0.4.23", default-features = false, features = ["clock"] }
clap = { version = "4.3.0", features = ["derive", "env"] }
cmac = "0.7.2"
configparser = "3"
Expand Down Expand Up @@ -57,8 +57,10 @@ rustls = "0.23.5"
rustls-pemfile = "2.1.2"
rustls-pemfile-old = { version = "1.0.2", package = "rustls-pemfile" }
sequoia-ipc = "0.30.1"
sequoia-openpgp = { version ="1.16.1", default-features = false, features = ["crypto-openssl"] }
serde = { version = "1.0", features = ["derive"]}
sequoia-openpgp = { version = "1.16.1", default-features = false, features = [
"crypto-openssl",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.96"
sha1 = "0.10.5"
sha2 = "0.10.7"
Expand All @@ -78,11 +80,14 @@ rayon = { version = "1.8.0", optional = true }
pcap = { version = "1.0.0", optional = true }
pnet_base = { version = "0.33.0", optional = true }
pnet = { version = "0.33.0", optional = true }
socket2 = {version = "0.5.2", features = ["all"], optional = true}
socket2 = { version = "0.5.2", features = ["all"], optional = true }
pnet_macros = { version = "0.33.0", optional = true }
pnet_macros_support = { version = "0.33.0", optional = true }

libssh-rs = {version = "~0.2", features = ["vendored-openssl", "vendored"], optional = true}
libssh-rs = { version = "~0.2", features = [
"vendored-openssl",
"vendored",
], optional = true }

nasl-function-proc-macro = { path = "crates/nasl-function-proc-macro" }
nasl-c-lib = { path = "crates/nasl-c-lib", optional = true }
Expand All @@ -92,22 +97,32 @@ rc4 = "0.1.0"

[workspace]
resolver = "2"
members = [
"crates/smoketest",
"crates/nasl-function-proc-macro",
]
members = ["crates/smoketest", "crates/nasl-function-proc-macro"]

[dev-dependencies]
tracing-test = "0.2.5"
criterion = "0"
insta = { version = "1.41.1", features = ["ron"] }

[features]
dep-graph-parallel = ["rayon", "crossbeam-channel"]
openvas_serde_support = []
serde_support = []
default = ["dep-graph-parallel", "openvas_serde_support", "enforce-no-trailing-arguments", "serde_support"]
default = [
"dep-graph-parallel",
"openvas_serde_support",
"enforce-no-trailing-arguments",
"serde_support",
]

nasl-builtin-raw-ip = ["pcap", "pnet_base", "pnet", "socket2", "pnet_macros", "pnet_macros_support",]
nasl-builtin-raw-ip = [
"pcap",
"pnet_base",
"pnet",
"socket2",
"pnet_macros",
"pnet_macros_support",
]
nasl-builtin-ssh = ["libssh-rs"]
experimental = ["nasl-builtin-raw-ip", "nasl-builtin-ssh", "nasl-c-lib"]

Expand Down
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_add.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a + 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_array.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a[1]
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_assign.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a = 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_assign_return.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
--a
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_block.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
{ ... }
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_break.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
break
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_call.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a();
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_continue.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
continue
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_declare.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
local_var a
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_div.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a / 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_exit.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
exit(0);
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_for.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
for (i = 0; i < 10; i++) { a }
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_foreach.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
foreach a(b) {c}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
function a((b)) { ... }
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_if.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
if (a) b else c
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_include.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
include("test.inc");
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_modulo.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a % 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_mul.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a * 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_named_parameter.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a: b
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_no_op.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
NoOp
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_parameter.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
(a, b)
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_primitive.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_repeat.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
repeat a until b
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_return.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
return 0;
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_return_assign.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a++
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_sub.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a - 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_variable.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a
Loading

0 comments on commit eb7fa2c

Please sign in to comment.