mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 13:28:30 +00:00
fix code format
This commit is contained in:
@@ -126,19 +126,27 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
||||
let chars: Vec<char> = text.chars().collect();
|
||||
for i in 0..chars.len() {
|
||||
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
|
||||
}
|
||||
target_end = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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 in_escape = false;
|
||||
|
||||
|
||||
for c in deps_str.chars() {
|
||||
if in_escape {
|
||||
if c != '\n' && c != '\r' {
|
||||
@@ -162,7 +170,6 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
||||
deps
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -214,7 +221,10 @@ mod tests {
|
||||
let src = dir.join("test.c");
|
||||
fs::write(&src, "int main() {}").unwrap();
|
||||
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]
|
||||
@@ -226,7 +236,10 @@ mod tests {
|
||||
// Sleep briefly to ensure mtime difference
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
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]
|
||||
@@ -237,7 +250,10 @@ mod tests {
|
||||
fs::write(&obj, "").unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
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]
|
||||
@@ -380,16 +396,26 @@ mod tests {
|
||||
fs::write(&header, "#define A 1").unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
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();
|
||||
|
||||
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));
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -212,20 +212,21 @@ fn build_objects(
|
||||
let output = cmd.output().map_err(|err| format!("Build failed: {err}"))?;
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
|
||||
let mut headers = Vec::new();
|
||||
let mut clean_stdout = String::new();
|
||||
for line in stdout.lines() {
|
||||
if let Some(stripped) = line.strip_prefix("Note: including file:") {
|
||||
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());
|
||||
} else {
|
||||
clean_stdout.push_str(line);
|
||||
clean_stdout.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if !output.status.success() {
|
||||
eprint!("{}", clean_stdout);
|
||||
eprint!("{}", stderr);
|
||||
@@ -233,7 +234,10 @@ fn build_objects(
|
||||
} else {
|
||||
let trimmed_out = clean_stdout.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 {
|
||||
print!("{}", clean_stdout);
|
||||
}
|
||||
@@ -241,7 +245,7 @@ fn build_objects(
|
||||
eprintln!("{}", trimmed_err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let d_path = Path::new(&obj_path).with_extension("d");
|
||||
let mut d_content = format!("{}: \\\n", obj_path.replace('\\', "/"));
|
||||
for h in headers {
|
||||
|
||||
@@ -588,4 +588,3 @@ mod tests {
|
||||
assert!(config.check(), "valid config should return true");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bin_path_release() {
|
||||
assert_eq!(
|
||||
bin_path("release", "hello", None),
|
||||
"./target/release/hello"
|
||||
);
|
||||
assert_eq!(bin_path("release", "hello", None), "./target/release/hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -75,4 +72,3 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,10 +122,7 @@ fn run_without_toml_fails() {
|
||||
fn clean_without_toml_fails() {
|
||||
let dir = unique_sandbox_dir("clean_no_toml");
|
||||
let out = run_dcr(&["clean"], &dir);
|
||||
assert!(
|
||||
!out.status.success(),
|
||||
"clean without dcr.toml should fail"
|
||||
);
|
||||
assert!(!out.status.success(), "clean without dcr.toml should fail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -148,7 +145,10 @@ fn init_nonempty_dir_fails() {
|
||||
// Put a file in the dir so it's not empty
|
||||
std::fs::write(dir.join("dummy.txt"), "x").expect("failed to write");
|
||||
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);
|
||||
assert!(
|
||||
stdout.contains("not empty") || stdout.contains("error"),
|
||||
@@ -163,10 +163,7 @@ fn build_unknown_flag_fails() {
|
||||
let out = run_dcr(&["init"], &dir);
|
||||
assert!(out.status.success(), "init should succeed");
|
||||
let out = run_dcr(&["build", "--foobar"], &dir);
|
||||
assert!(
|
||||
!out.status.success(),
|
||||
"build with unknown flag should fail"
|
||||
);
|
||||
assert!(!out.status.success(), "build with unknown flag should fail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -183,18 +180,12 @@ fn run_library_project_fails() {
|
||||
// Edit dcr.toml to set kind = "staticlib"
|
||||
let toml_path = dir.join("dcr.toml");
|
||||
let toml = std::fs::read_to_string(&toml_path).expect("failed to read dcr.toml");
|
||||
let updated = toml.replace(
|
||||
"kind = \"bin\"",
|
||||
"kind = \"staticlib\"",
|
||||
);
|
||||
let updated = toml.replace("kind = \"bin\"", "kind = \"staticlib\"");
|
||||
std::fs::write(&toml_path, updated).expect("failed to write dcr.toml");
|
||||
|
||||
let envs = [("DCR_COMPILER", compiler)];
|
||||
let out = run_dcr_env(&["run"], &dir, &envs);
|
||||
assert!(
|
||||
!out.status.success(),
|
||||
"dcr run on staticlib should fail"
|
||||
);
|
||||
assert!(!out.status.success(), "dcr run on staticlib should fail");
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(
|
||||
stdout.contains("library") || stdout.contains("Cannot run"),
|
||||
@@ -231,10 +222,7 @@ fn clean_specific_profile() {
|
||||
fn new_no_name_fails() {
|
||||
let dir = unique_sandbox_dir("new_noname");
|
||||
let out = run_dcr(&["new"], &dir);
|
||||
assert!(
|
||||
!out.status.success(),
|
||||
"dcr new without name should fail"
|
||||
);
|
||||
assert!(!out.status.success(), "dcr new without name should fail");
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(
|
||||
stdout.contains("not specified") || stdout.contains("error"),
|
||||
@@ -266,11 +254,7 @@ fn staticlib_build() {
|
||||
.map(|entries| {
|
||||
entries
|
||||
.filter_map(|e| e.ok())
|
||||
.any(|e| {
|
||||
e.file_name()
|
||||
.to_string_lossy()
|
||||
.ends_with(".a")
|
||||
})
|
||||
.any(|e| e.file_name().to_string_lossy().ends_with(".a"))
|
||||
})
|
||||
.unwrap_or(false);
|
||||
assert!(has_lib, "staticlib should produce a .a file");
|
||||
@@ -302,6 +286,12 @@ fn version_contains_version_string() {
|
||||
assert!(out.status.success());
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
// Should contain version like "dcr 0.2.8 (target)"
|
||||
assert!(stdout.contains("dcr "), "version output should start with 'dcr '");
|
||||
assert!(stdout.contains('.'), "version output should contain a version number");
|
||||
assert!(
|
||||
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