Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests to make precommit.sh run on Windows #1831

Merged
merged 7 commits into from
May 29, 2024
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
9 changes: 5 additions & 4 deletions opentelemetry-prometheus/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,18 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &'
let metric_families = registry.gather();
encoder.encode(&metric_families, &mut output).unwrap();

let expected = get_platform_specific_string(expected);
lalitb marked this conversation as resolved.
Show resolved Hide resolved
let output_string = get_platform_specific_string(String::from_utf8(output).unwrap());

assert_eq!(output_string, expected, "{name}");
}

/// Returns a String which uses the platform specific new line feed character.
fn get_platform_specific_string(input: String) -> String {
if cfg!(windows) {
input.replace('\n', "\r\n")
} else {
input
if cfg!(windows) && !input.ends_with("\r\n") && input.ends_with('\n') {
return input.replace('\n', "\r\n");
}
input
}

#[test]
Expand Down Expand Up @@ -812,6 +812,7 @@ fn duplicate_metrics() {
.expected_files
.into_iter()
.map(|f| fs::read_to_string(Path::new("./tests/data").join(f)).expect(f))
.map(get_platform_specific_string)
.collect();
gather_and_compare_multi(registry, possible_matches, tc.name);
}
Expand Down
11 changes: 5 additions & 6 deletions opentelemetry-proto/tests/grpc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];

#[test]
fn build_tonic() {
let before_build = build_content_map(TONIC_OUT_DIR, false);
let before_build = build_content_map(TONIC_OUT_DIR, true);

let out_dir = TempDir::new().expect("failed to create temp dir to store the generated files");

Expand Down Expand Up @@ -130,13 +130,12 @@ fn build_content_map(path: impl AsRef<Path>, normalize_line_feed: bool) -> HashM
.collect()
}

/// Returns a String with the platform specific new line feed character.
/// Returns a String which uses the platform specific new line feed character.
fn get_platform_specific_string(input: String) -> String {
if cfg!(windows) {
input.replace('\n', "\r\n")
} else {
input
if cfg!(windows) && !input.ends_with("\r\n") && input.ends_with('\n') {
return input.replace('\n', "\r\n");
}
input
}

fn ensure_files_are_same(
Expand Down
Loading