Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 34 additions & 3 deletions lib/bencher_adapter/src/adapters/c_sharp/dot_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub struct Benchmarks(pub Vec<Benchmark>);
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct Benchmark {
pub namespace: BenchmarkName,
#[serde(rename = "Namespace")]
pub opt_namespace: Option<BenchmarkName>,
pub method: BenchmarkName,
pub statistics: Statistics,
}
Expand All @@ -57,7 +58,7 @@ impl DotNet {
let mut benchmark_metrics = Vec::with_capacity(benchmarks.len());
for benchmark in benchmarks {
let Benchmark {
namespace: mut benchmark_name,
opt_namespace,
method,
statistics,
} = benchmark;
Expand All @@ -68,7 +69,13 @@ impl DotNet {
interquartile_range,
} = statistics;

benchmark_name.try_push('.', &method)?;
let benchmark_name = match opt_namespace {
Some(mut name) => {
name.try_push('.', &method)?;
name
},
None => method,
};

// JSON output is always in nanos
let units = Units::Nano;
Expand Down Expand Up @@ -121,6 +128,30 @@ pub(crate) mod test_c_sharp_dot_net {
format!("./tool_output/c_sharp/dot_net/{suffix}.json")
}

#[test]
fn test_adapter_c_sharp_dot_net_null_namespace() {
let null_namespace = "null_namespace";
let file_path = file_path(null_namespace);

let results = convert_c_sharp_dot_net(null_namespace);
validate_adapter_c_sharp_dot_net_null_namespace(&results);

let results = opt_convert_file_path::<AdapterCSharpDotNet>(
&file_path,
Settings {
average: Some(JsonAverage::Mean),
},
)
.unwrap();

validate_adapter_c_sharp_dot_net_null_namespace(&results);
}

fn validate_adapter_c_sharp_dot_net_null_namespace(results: &AdapterResults) {
assert_eq!(results.inner.len(), 1);
assert!(results.get("NullNamespaceMethod").is_some());
}

#[test]
fn test_adapter_c_sharp_dot_net_two() {
let two = "two";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"HostEnvironmentInfo": {
},
"Benchmarks": [
{
"Namespace": null,
"Method": "NullNamespaceMethod",
"Statistics": {
"Median": 0,
"Mean": 0,
"InterquartileRange": 0,
"StandardDeviation": 0
}
}
]
}