mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 14:38:30 +00:00
fix code format
This commit is contained in:
@@ -126,7 +126,11 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
|||||||
let chars: Vec<char> = text.chars().collect();
|
let chars: Vec<char> = text.chars().collect();
|
||||||
for i in 0..chars.len() {
|
for i in 0..chars.len() {
|
||||||
if chars[i] == ':' {
|
if chars[i] == ':' {
|
||||||
if i == 1 && chars[0].is_ascii_alphabetic() && i + 1 < chars.len() && (chars[i+1] == '\\' || chars[i+1] == '/') {
|
if i == 1
|
||||||
|
&& chars[0].is_ascii_alphabetic()
|
||||||
|
&& i + 1 < chars.len()
|
||||||
|
&& (chars[i + 1] == '\\' || chars[i + 1] == '/')
|
||||||
|
{
|
||||||
continue; // Windows drive letter
|
continue; // Windows drive letter
|
||||||
}
|
}
|
||||||
target_end = i + 1;
|
target_end = i + 1;
|
||||||
@@ -134,7 +138,11 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let deps_str = if target_end > 0 { &text[target_end..] } else { &text };
|
let deps_str = if target_end > 0 {
|
||||||
|
&text[target_end..]
|
||||||
|
} else {
|
||||||
|
&text
|
||||||
|
};
|
||||||
|
|
||||||
let mut current_path = String::new();
|
let mut current_path = String::new();
|
||||||
let mut in_escape = false;
|
let mut in_escape = false;
|
||||||
@@ -162,7 +170,6 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
|||||||
deps
|
deps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -214,7 +221,10 @@ mod tests {
|
|||||||
let src = dir.join("test.c");
|
let src = dir.join("test.c");
|
||||||
fs::write(&src, "int main() {}").unwrap();
|
fs::write(&src, "int main() {}").unwrap();
|
||||||
let obj = dir.join("test.o");
|
let obj = dir.join("test.o");
|
||||||
assert!(needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()));
|
assert!(needs_rebuild(
|
||||||
|
&src.to_string_lossy(),
|
||||||
|
&obj.to_string_lossy()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -226,7 +236,10 @@ mod tests {
|
|||||||
// Sleep briefly to ensure mtime difference
|
// Sleep briefly to ensure mtime difference
|
||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
fs::write(&obj, "").unwrap();
|
fs::write(&obj, "").unwrap();
|
||||||
assert!(!needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()));
|
assert!(!needs_rebuild(
|
||||||
|
&src.to_string_lossy(),
|
||||||
|
&obj.to_string_lossy()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -237,7 +250,10 @@ mod tests {
|
|||||||
fs::write(&obj, "").unwrap();
|
fs::write(&obj, "").unwrap();
|
||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
fs::write(&src, "int main() { return 1; }").unwrap();
|
fs::write(&src, "int main() { return 1; }").unwrap();
|
||||||
assert!(needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()));
|
assert!(needs_rebuild(
|
||||||
|
&src.to_string_lossy(),
|
||||||
|
&obj.to_string_lossy()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -381,15 +397,25 @@ mod tests {
|
|||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
fs::write(&obj, "").unwrap();
|
fs::write(&obj, "").unwrap();
|
||||||
|
|
||||||
let d_content = format!("{}: {} {}", obj.to_string_lossy(), src.to_string_lossy(), header.to_string_lossy());
|
let d_content = format!(
|
||||||
|
"{}: {} {}",
|
||||||
|
obj.to_string_lossy(),
|
||||||
|
src.to_string_lossy(),
|
||||||
|
header.to_string_lossy()
|
||||||
|
);
|
||||||
fs::write(&d_file, d_content).unwrap();
|
fs::write(&d_file, d_content).unwrap();
|
||||||
|
|
||||||
assert!(!needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()), "should be fresh");
|
assert!(
|
||||||
|
!needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()),
|
||||||
|
"should be fresh"
|
||||||
|
);
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
fs::write(&header, "#define A 2").unwrap(); // modify header
|
fs::write(&header, "#define A 2").unwrap(); // modify header
|
||||||
|
|
||||||
assert!(needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()), "changed header should trigger rebuild");
|
assert!(
|
||||||
|
needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()),
|
||||||
|
"changed header should trigger rebuild"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -218,7 +218,8 @@ fn build_objects(
|
|||||||
for line in stdout.lines() {
|
for line in stdout.lines() {
|
||||||
if let Some(stripped) = line.strip_prefix("Note: including file:") {
|
if let Some(stripped) = line.strip_prefix("Note: including file:") {
|
||||||
headers.push(stripped.trim().to_string());
|
headers.push(stripped.trim().to_string());
|
||||||
} else if let Some(stripped) = line.strip_prefix("Примечание: включение файла:") {
|
} else if let Some(stripped) = line.strip_prefix("Примечание: включение файла:")
|
||||||
|
{
|
||||||
headers.push(stripped.trim().to_string());
|
headers.push(stripped.trim().to_string());
|
||||||
} else {
|
} else {
|
||||||
clean_stdout.push_str(line);
|
clean_stdout.push_str(line);
|
||||||
@@ -233,7 +234,10 @@ fn build_objects(
|
|||||||
} else {
|
} else {
|
||||||
let trimmed_out = clean_stdout.trim();
|
let trimmed_out = clean_stdout.trim();
|
||||||
let trimmed_err = stderr.trim();
|
let trimmed_err = stderr.trim();
|
||||||
let src_filename = Path::new(source).file_name().and_then(|v| v.to_str()).unwrap_or("");
|
let src_filename = Path::new(source)
|
||||||
|
.file_name()
|
||||||
|
.and_then(|v| v.to_str())
|
||||||
|
.unwrap_or("");
|
||||||
if !trimmed_out.is_empty() && trimmed_out != src_filename {
|
if !trimmed_out.is_empty() && trimmed_out != src_filename {
|
||||||
print!("{}", clean_stdout);
|
print!("{}", clean_stdout);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -588,4 +588,3 @@ mod tests {
|
|||||||
assert!(config.check(), "valid config should return true");
|
assert!(config.check(), "valid config should return true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bin_path_release() {
|
fn bin_path_release() {
|
||||||
assert_eq!(
|
assert_eq!(bin_path("release", "hello", None), "./target/release/hello");
|
||||||
bin_path("release", "hello", None),
|
|
||||||
"./target/release/hello"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -75,4 +72,3 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,10 +122,7 @@ fn run_without_toml_fails() {
|
|||||||
fn clean_without_toml_fails() {
|
fn clean_without_toml_fails() {
|
||||||
let dir = unique_sandbox_dir("clean_no_toml");
|
let dir = unique_sandbox_dir("clean_no_toml");
|
||||||
let out = run_dcr(&["clean"], &dir);
|
let out = run_dcr(&["clean"], &dir);
|
||||||
assert!(
|
assert!(!out.status.success(), "clean without dcr.toml should fail");
|
||||||
!out.status.success(),
|
|
||||||
"clean without dcr.toml should fail"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -148,7 +145,10 @@ fn init_nonempty_dir_fails() {
|
|||||||
// Put a file in the dir so it's not empty
|
// Put a file in the dir so it's not empty
|
||||||
std::fs::write(dir.join("dummy.txt"), "x").expect("failed to write");
|
std::fs::write(dir.join("dummy.txt"), "x").expect("failed to write");
|
||||||
let out = run_dcr(&["init"], &dir);
|
let out = run_dcr(&["init"], &dir);
|
||||||
assert!(!out.status.success(), "dcr init in non-empty dir should fail");
|
assert!(
|
||||||
|
!out.status.success(),
|
||||||
|
"dcr init in non-empty dir should fail"
|
||||||
|
);
|
||||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
assert!(
|
assert!(
|
||||||
stdout.contains("not empty") || stdout.contains("error"),
|
stdout.contains("not empty") || stdout.contains("error"),
|
||||||
@@ -163,10 +163,7 @@ fn build_unknown_flag_fails() {
|
|||||||
let out = run_dcr(&["init"], &dir);
|
let out = run_dcr(&["init"], &dir);
|
||||||
assert!(out.status.success(), "init should succeed");
|
assert!(out.status.success(), "init should succeed");
|
||||||
let out = run_dcr(&["build", "--foobar"], &dir);
|
let out = run_dcr(&["build", "--foobar"], &dir);
|
||||||
assert!(
|
assert!(!out.status.success(), "build with unknown flag should fail");
|
||||||
!out.status.success(),
|
|
||||||
"build with unknown flag should fail"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -183,18 +180,12 @@ fn run_library_project_fails() {
|
|||||||
// Edit dcr.toml to set kind = "staticlib"
|
// Edit dcr.toml to set kind = "staticlib"
|
||||||
let toml_path = dir.join("dcr.toml");
|
let toml_path = dir.join("dcr.toml");
|
||||||
let toml = std::fs::read_to_string(&toml_path).expect("failed to read dcr.toml");
|
let toml = std::fs::read_to_string(&toml_path).expect("failed to read dcr.toml");
|
||||||
let updated = toml.replace(
|
let updated = toml.replace("kind = \"bin\"", "kind = \"staticlib\"");
|
||||||
"kind = \"bin\"",
|
|
||||||
"kind = \"staticlib\"",
|
|
||||||
);
|
|
||||||
std::fs::write(&toml_path, updated).expect("failed to write dcr.toml");
|
std::fs::write(&toml_path, updated).expect("failed to write dcr.toml");
|
||||||
|
|
||||||
let envs = [("DCR_COMPILER", compiler)];
|
let envs = [("DCR_COMPILER", compiler)];
|
||||||
let out = run_dcr_env(&["run"], &dir, &envs);
|
let out = run_dcr_env(&["run"], &dir, &envs);
|
||||||
assert!(
|
assert!(!out.status.success(), "dcr run on staticlib should fail");
|
||||||
!out.status.success(),
|
|
||||||
"dcr run on staticlib should fail"
|
|
||||||
);
|
|
||||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
assert!(
|
assert!(
|
||||||
stdout.contains("library") || stdout.contains("Cannot run"),
|
stdout.contains("library") || stdout.contains("Cannot run"),
|
||||||
@@ -231,10 +222,7 @@ fn clean_specific_profile() {
|
|||||||
fn new_no_name_fails() {
|
fn new_no_name_fails() {
|
||||||
let dir = unique_sandbox_dir("new_noname");
|
let dir = unique_sandbox_dir("new_noname");
|
||||||
let out = run_dcr(&["new"], &dir);
|
let out = run_dcr(&["new"], &dir);
|
||||||
assert!(
|
assert!(!out.status.success(), "dcr new without name should fail");
|
||||||
!out.status.success(),
|
|
||||||
"dcr new without name should fail"
|
|
||||||
);
|
|
||||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
assert!(
|
assert!(
|
||||||
stdout.contains("not specified") || stdout.contains("error"),
|
stdout.contains("not specified") || stdout.contains("error"),
|
||||||
@@ -266,11 +254,7 @@ fn staticlib_build() {
|
|||||||
.map(|entries| {
|
.map(|entries| {
|
||||||
entries
|
entries
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
.any(|e| {
|
.any(|e| e.file_name().to_string_lossy().ends_with(".a"))
|
||||||
e.file_name()
|
|
||||||
.to_string_lossy()
|
|
||||||
.ends_with(".a")
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
assert!(has_lib, "staticlib should produce a .a file");
|
assert!(has_lib, "staticlib should produce a .a file");
|
||||||
@@ -302,6 +286,12 @@ fn version_contains_version_string() {
|
|||||||
assert!(out.status.success());
|
assert!(out.status.success());
|
||||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
// Should contain version like "dcr 0.2.8 (target)"
|
// Should contain version like "dcr 0.2.8 (target)"
|
||||||
assert!(stdout.contains("dcr "), "version output should start with 'dcr '");
|
assert!(
|
||||||
assert!(stdout.contains('.'), "version output should contain a version number");
|
stdout.contains("dcr "),
|
||||||
|
"version output should start with 'dcr '"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
stdout.contains('.'),
|
||||||
|
"version output should contain a version number"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user