Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Replace usages of ::std::env::temp_dir with tempdir crate in tests #6215

Closed
wants to merge 1 commit into from

Conversation

nicolasochem
Copy link
Contributor

Fix #6147

@parity-cla-bot
Copy link

It looks like @nicolasochem signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

assert_eq!(ethash.cache.lock().recent_epoch.unwrap(), 2);
assert_eq!(ethash.cache.lock().prev_epoch.unwrap(), 0);
#[cfg(test)]
mod test {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convention would call this "mod tests", here and other places

}
#[cfg(test)]
mod test {
extern crate tempdir;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paritytech/core-devs any opinion on including the crate within the module? I'd personally prefer it in the crate root.

Copy link
Collaborator

@debris debris Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but only if it's used in more than 1 place by this crate

//ethash/src/lib.rs

#[cfg(test)]
extern crate tempdir;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, i was leaning that direction as well. although as Rust will (in a few versions) infer extern crate declarations, I thought it might be best to leave them as easy to hunt down as possible

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really? is there an rfc for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is. I personally hope it doesn't happen, although that might just be status quo bias talking.

It's not a certainty though, the PR is yet to be merged. We have this pattern all over the codebase already:

➤ rg '#\[cfg' -A 2 | rg '\bmod\b' -A 1 | rg 'extern crate' | wc -l
10

@rphmeier rphmeier added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. M4-core ⛓ Core client code / Rust. labels Aug 2, 2017
fn test_get_cache_size() {
// https://github.com/ethereum/wiki/wiki/Ethash/ef6b93f9596746a088ea95d01ca2778be43ae68f#data-sizes
assert_eq!(16776896usize, get_cache_size(0));
assert_eq!(16776896usize, get_cache_size(1));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

let boundary = [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3e, 0x9b, 0x6c, 0x69, 0xbc, 0x2c, 0xe2, 0xa2, 0x4a, 0x8e, 0x95, 0x69, 0xef, 0xc7, 0xd7, 0x1b, 0x33, 0x35, 0xdf, 0x36, 0x8c, 0x9a, 0xe9, 0x7e, 0x53, 0x84];
let nonce = 0xd7b3ac70a301a249;
// difficulty = 0x085657254bd9u64;
let light = Light::new(TempDir::new("").unwrap(), 486382);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will really work, it's dropped right after start so if the test passes it means that it doesn't really use the directory anyway or it creates it and never removes in which case it doesn't make it any better than ::std::env::temp_dir()
(here and other occurrences)

let mut dir = env::temp_dir();
dir.push(format!("{:x}-{:x}", rng.next_u64(), rng.next_u64()));
dir
let temp_path = TempDir::new("").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Identation
  2. The directory is not really removed after the test so don't see any point in using the crate here (in the way it's currently used)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module can be removed entirely, cause it duplicates TempDir logic

@tomusdrw
Copy link
Collaborator

tomusdrw commented Sep 4, 2017

Any progress on that one?

@gavofyork
Copy link
Contributor

stale. closing.

@gavofyork gavofyork closed this Sep 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants