-
Notifications
You must be signed in to change notification settings - Fork 55
Create RFC Simple Tests #57
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
Open
webdesus
wants to merge
2
commits into
master
Choose a base branch
from
RFC-Simle-Test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Simplify tests | ||
| ## Summary | ||
| Using declarative approach for create and check folders content. For declaration description using yaml string data | ||
|
|
||
| ### Example YAML data: | ||
| ```yaml | ||
| Test name for folder: "FOLDER" | ||
| Test name for file: "FILE" | ||
| Another file: | ||
| - type: "FILE" | ||
| - content: "blah blah blah" | ||
| Another folder: "FOLDER" | ||
| ``` | ||
|
|
||
| ## Motivation | ||
| I think every to agree with me, that now we have many code noise in tests. | ||
| ### Example: | ||
| ```rust | ||
| let mut test_file = PathBuf::from(TEST_FOLDER); | ||
| test_file.push("it_read_and_write_work"); | ||
| test_file.push("test.txt"); | ||
| fs_extra::dir::create_all(test_file.parent().unwrap(), true).unwrap(); | ||
| let content1 = "test_1"; | ||
| let content2 = "test_2"; | ||
| write_all(&test_file, &content1).unwrap(); | ||
| assert!(test_file.exists()); | ||
| let read1 = read_to_string(&test_file).unwrap(); | ||
| assert_eq!(content1, read1); | ||
| write_all(&test_file, &content2).unwrap(); | ||
| let read2 = read_to_string(&test_file).unwrap(); | ||
| assert_eq!(content2, read2); | ||
| ``` | ||
|
|
||
| In new way this code can be like: | ||
|
|
||
| ```rust | ||
| let t = TestFS::new("it_read_and_write_work", r#" | ||
| test.txt: | ||
| - type: "FILE" | ||
| - content: "test_1""#; | ||
| let test_file = t.getPath("test.txt") | ||
| let data = read_to_string(&test_file).unwrap(); | ||
| assert_eq!("test_1", data); | ||
| write_all(&test_file, "test_2").unwrap(); | ||
| data = read_to_string(&test_file).unwrap(); | ||
| assert_eq!("test_2", data); | ||
| ``` | ||
|
|
||
| I think we can change it and make tests more readable, and increase speed to write new tests using new approach. | ||
|
|
||
| ### Another Example: | ||
| ```rust | ||
| let mut test_file = PathBuf::from(TEST_FOLDER); | ||
| test_file.push("it_copy_work"); | ||
| let mut test_file_out = test_file.clone(); | ||
| test_file.push("test.txt"); | ||
| test_file_out.push("out"); | ||
| test_file_out.push("test.txt"); | ||
| fs_extra::dir::create_all(&test_file.parent().unwrap(), true).unwrap(); | ||
| fs_extra::dir::create_all(&test_file_out.parent().unwrap(), true).unwrap(); | ||
|
|
||
| write_all(&test_file, "test_data").unwrap(); | ||
| assert!(test_file.exists()); | ||
| assert!(!test_file_out.exists()); | ||
| let options = CopyOptions::new(); | ||
| copy(&test_file, &test_file_out, &options).unwrap(); | ||
| assert!(test_file.exists()); | ||
| assert!(test_file_out.exists()); | ||
| assert_eq!(test_file.file_name(), test_file_out.file_name()); | ||
| assert!(files_eq(test_file, test_file_out).unwrap()); | ||
| ``` | ||
| RFC version: | ||
| ```rust | ||
| let t = TestFS::new("it_copy_work", r#" | ||
| test.txt: | ||
| - type: "FILE" | ||
| - content: "test_data" | ||
| out: "FOLDER""#; | ||
|
webdesus marked this conversation as resolved.
Outdated
|
||
| let options = CopyOptions::new(); | ||
| let test_file = t.getPath("test.txt") | ||
| let test_file_out = t.getPath("out/test.txt") | ||
| copy(&test_file, &test_file_out, &options).unwrap(); | ||
| t.check(r#" | ||
| test.txt: | ||
| - type: "FILE" | ||
| - content: "test_data" | ||
| out: "FOLDER" | ||
|
webdesus marked this conversation as resolved.
|
||
| test.txt: | ||
| - type: "FILE" | ||
| - content: "test_data""#); | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.