Skip to content

Commit

Permalink
Take the nuclear option to fix path normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Jul 10, 2024
1 parent a854939 commit 8555d79
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ source: tests/rojo_test/syncback_util.rs
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "src\\csv.csv"
- "src\\csv_init\\init.csv"
- "src\\dir\\client_script.client.luau"
- "src\\dir\\init_client_script\\init.client.luau"
- "src\\dir\\init_module_script\\init.luau"
- "src\\dir\\init_server_script\\init.server.luau"
- "src\\dir\\module_script.luau"
- "src\\dir\\server_script.server.luau"
- "src\\model_json.model.json"
- "src\\project_json.project.json"
- "src\\rbxm.rbxm"
- "src\\rbxmx.rbxmx"
- "src\\text.txt"
- src/csv.csv
- src/csv_init/init.csv
- src/dir/client_script.client.luau
- src/dir/init_client_script/init.client.luau
- src/dir/init_module_script/init.luau
- src/dir/init_server_script/init.server.luau
- src/dir/module_script.luau
- src/dir/server_script.server.luau
- src/model_json.model.json
- src/project_json.project.json
- src/rbxm.rbxm
- src/rbxmx.rbxmx
- src/text.txt
added_dirs:
- src
- "src\\csv_init"
- "src\\dir"
- "src\\dir\\init_client_script"
- "src\\dir\\init_module_script"
- "src\\dir\\init_server_script"
- src/csv_init
- src/dir
- src/dir/init_client_script
- src/dir/init_module_script
- src/dir/init_server_script
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "Lighting\\Atmosphere.model.json"
- "Lighting\\Bloom.model.json"
- "Lighting\\DepthOfField.model.json"
- "Lighting\\Sky.model.json"
- "Lighting\\SunRays.model.json"
- "Workspace\\Baseplate.rbxm"
- "Workspace\\Camera.rbxm"
- "Workspace\\SpawnLocation.rbxm"
- "Workspace\\Terrain.rbxm"
- Lighting/Atmosphere.model.json
- Lighting/Bloom.model.json
- Lighting/DepthOfField.model.json
- Lighting/Sky.model.json
- Lighting/SunRays.model.json
- Workspace/Baseplate.rbxm
- Workspace/Camera.rbxm
- Workspace/SpawnLocation.rbxm
- Workspace/Terrain.rbxm
- default.project.json
added_dirs:
- Lighting
- Workspace
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "OnlyOneCopy\\child_of_one.luau"
- "ReplicatedStorage\\child_replicated_storage.luau"
- OnlyOneCopy/child_of_one.luau
- ReplicatedStorage/child_replicated_storage.luau
added_dirs:
- OnlyOneCopy
- ReplicatedStorage
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- default.project.json
- "src\\integer.model.json"
- src/integer.model.json
added_dirs:
- src
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "src/modules\\ClientModule.luau"
- "src/modules\\ServerModule.luau"
- src/modules/ClientModule.luau
- src/modules/ServerModule.luau
added_dirs:
- src/modules
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
added_files:
- src/client_script.client.luau
- src/csv.csv
- "src/csv_init\\init.csv"
- "src/init_client_script\\init.client.luau"
- "src/init_module_script\\init.luau"
- "src/init_server_script\\init.server.luau"
- src/csv_init/init.csv
- src/init_client_script/init.client.luau
- src/init_module_script/init.luau
- src/init_server_script/init.server.luau
- src/model_json.model.json
- src/module_script.luau
- src/project_json.project.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/rojo_test/syncback_util.rs
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "src\\init.luau"
- src/init.luau
added_dirs:
- src
removed_files: []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "ReplicatedStorage\\ChildWithDuplicates.rbxm"
- "ReplicatedStorage\\ChildWithoutDuplicates\\Child\\.gitkeep"
- ReplicatedStorage/ChildWithDuplicates.rbxm
- ReplicatedStorage/ChildWithoutDuplicates/Child/.gitkeep
added_dirs:
- ReplicatedStorage
- "ReplicatedStorage\\ChildWithoutDuplicates"
- "ReplicatedStorage\\ChildWithoutDuplicates\\Child"
- ReplicatedStorage/ChildWithoutDuplicates
- ReplicatedStorage/ChildWithoutDuplicates/Child
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "src\\pointer.model.json"
- "src\\target.model.json"
- src/pointer.model.json
- src/target.model.json
added_dirs:
- src
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- default.project.json
- "src\\Camera.rbxm"
- "src\\Terrain.rbxm"
- "src\\pointer.model.json"
- "src\\target.meta.json"
- "src\\target.txt"
- src/Camera.rbxm
- src/Terrain.rbxm
- src/pointer.model.json
- src/target.meta.json
- src/target.txt
added_dirs:
- src
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "src\\pointer.model.json"
- "src\\target.model.json"
- src/pointer.model.json
- src/target.model.json
added_dirs:
- src
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "Workspace\\Baseplate.model.json"
- "Workspace\\Terrain.rbxm"
- Workspace/Baseplate.model.json
- Workspace/Terrain.rbxm
- default.project.json
added_dirs:
- Workspace
removed_files: []
removed_dirs: []

34 changes: 34 additions & 0 deletions tests/rojo_test/io_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
process::Child,
};

use serde::{ser::SerializeSeq, Serialize, Serializer};
use walkdir::WalkDir;

pub static ROJO_PATH: &str = env!("CARGO_BIN_EXE_rojo");
Expand Down Expand Up @@ -67,3 +68,36 @@ impl Drop for KillOnDrop {
}
}
}

// Stolen from librojo::path_serializer
pub fn serialize_absolute<S, T>(path: T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<Path>,
{
let as_str = path
.as_ref()
.as_os_str()
.to_str()
.expect("Invalid Unicode in file path, cannot serialize");
let replaced = as_str.replace('\\', "/");

serializer.serialize_str(&replaced)
}

#[derive(Serialize)]
struct WithAbsolute<'a>(#[serde(serialize_with = "serialize_absolute")] &'a Path);

pub fn serialize_vec_absolute<S, T>(paths: &[T], serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<Path>,
{
let mut seq = serializer.serialize_seq(Some(paths.len()))?;

for path in paths {
seq.serialize_element(&WithAbsolute(path.as_ref()))?;
}

seq.end()
}
26 changes: 15 additions & 11 deletions tests/rojo_test/syncback_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use memofs::{InMemoryFs, IoResultExt, Vfs, VfsSnapshot};
use rbx_reflection::ReflectionDatabase;
use serde::Serialize;

use crate::rojo_test::io_util::SYNCBACK_TESTS_PATH;
use crate::rojo_test::io_util::{serialize_vec_absolute, SYNCBACK_TESTS_PATH};

const INPUT_FILE: &str = "input.rbxl";
const EXPECTED_DIR: &str = "expected";
Expand Down Expand Up @@ -184,30 +184,34 @@ fn normalize_line_endings(input: &Vec<u8>) -> Cow<Vec<u8>> {
}

#[derive(Default, Debug, Serialize)]
struct FsSnapshotVisual {
added_files: Vec<String>,
added_dirs: Vec<String>,
removed_files: Vec<String>,
removed_dirs: Vec<String>,
struct FsSnapshotVisual<'a> {
#[serde(serialize_with = "serialize_vec_absolute")]
added_files: Vec<&'a Path>,
#[serde(serialize_with = "serialize_vec_absolute")]
added_dirs: Vec<&'a Path>,
#[serde(serialize_with = "serialize_vec_absolute")]
removed_files: Vec<&'a Path>,
#[serde(serialize_with = "serialize_vec_absolute")]
removed_dirs: Vec<&'a Path>,
}

fn visualize_fs_snapshot(snapshot: &FsSnapshot, base_path: &Path) -> FsSnapshotVisual {
fn visualize_fs_snapshot<'a>(snapshot: &'a FsSnapshot, base_path: &Path) -> FsSnapshotVisual<'a> {
let mut added_files = Vec::new();
let mut added_dirs = Vec::new();
let mut removed_files = Vec::new();
let mut removed_dirs = Vec::new();

for file in snapshot.added_files() {
added_files.push(file.strip_prefix(base_path).unwrap().display().to_string())
added_files.push(file.strip_prefix(base_path).unwrap())
}
for file in snapshot.added_dirs() {
added_dirs.push(file.strip_prefix(base_path).unwrap().display().to_string())
added_dirs.push(file.strip_prefix(base_path).unwrap())
}
for file in snapshot.removed_dirs() {
removed_dirs.push(file.strip_prefix(base_path).unwrap().display().to_string())
removed_dirs.push(file.strip_prefix(base_path).unwrap())
}
for file in snapshot.removed_files() {
removed_files.push(file.strip_prefix(base_path).unwrap().display().to_string())
removed_files.push(file.strip_prefix(base_path).unwrap())
}

added_files.sort_unstable();
Expand Down

0 comments on commit 8555d79

Please sign in to comment.