• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

facet-rs / facet / 14449118429

14 Apr 2025 03:08PM UTC coverage: 26.422% (+0.05%) from 26.376%
14449118429

Pull #212

github

web-flow
Merge a17a0cb29 into e69296323
Pull Request #212: Allow implementing Facet on recursive/cyclic types

5 of 14 new or added lines in 7 files covered. (35.71%)

21 existing lines in 1 file now uncovered.

1686 of 6381 relevant lines covered (26.42%)

16.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/facet-codegen/src/readmes.rs
1
use facet_ansi::Stylize as _;
2
use log::{error, info};
3
use std::path::Path;
4
use std::time::Instant;
5

6
use crate::Options;
7
use crate::write_if_different;
8

9
pub(crate) fn generate_readme_files(opts: Options) -> bool {
×
10
    let mut has_diffs = false;
×
11

12
    let start = Instant::now();
×
13

14
    // Get all crate directories in the workspace
15
    let workspace_dir = std::env::current_dir().unwrap();
×
16
    let entries = fs_err::read_dir(&workspace_dir).expect("Failed to read workspace directory");
×
17

18
    // Keep track of all crates we generate READMEs for
19
    let mut generated_crates = Vec::new();
×
20

21
    let template_name = "README.md.in";
×
22

23
    // Process each crate in the workspace
24
    for entry in entries {
×
25
        let entry = entry.expect("Failed to read directory entry");
×
26
        let path = entry.path();
×
27

28
        // Skip non-directories and entries starting with '.' or '_'
29
        if !path.is_dir()
×
30
            || path.file_name().is_some_and(|name| {
×
31
                let name = name.to_string_lossy();
×
32
                name.starts_with('.') || name.starts_with('_')
×
33
            })
34
        {
35
            continue;
×
36
        }
37

38
        // Skip target directory
39
        let dir_name = path.file_name().unwrap().to_string_lossy();
×
40
        if dir_name == "target" {
×
41
            continue;
×
42
        }
43

44
        // Check if this is a crate directory (has a Cargo.toml)
45
        let cargo_toml_path = path.join("Cargo.toml");
×
46
        if !cargo_toml_path.exists() {
×
47
            continue;
×
48
        }
49

50
        // Get crate name from directory name
51
        let crate_name = dir_name.to_string();
×
52

53
        // Check for templates
54
        let template_path = if crate_name == "facet" {
×
55
            Path::new(template_name).to_path_buf()
×
56
        } else {
57
            path.join(template_name)
×
58
        };
59

60
        if template_path.exists() {
×
61
            process_readme_template(&path, &template_path, &mut has_diffs, opts.clone());
×
62
            generated_crates.push(crate_name);
×
63
        } else {
64
            error!("🚫 Missing template: {}", template_path.display().red());
×
65
            panic!();
×
66
        }
67
    }
68

69
    // Generate workspace README, too (which is the same as the `facet` crate)
70
    let workspace_template_path = workspace_dir.join(template_name);
×
71
    if !workspace_template_path.exists() {
×
72
        error!(
×
73
            "🚫 {}",
×
UNCOV
74
            format!(
×
UNCOV
75
                "Template file {} not found for workspace. We looked at {}",
×
76
                template_name,
×
77
                workspace_template_path.display()
×
78
            )
UNCOV
79
            .red()
×
80
        );
UNCOV
81
        panic!();
×
82
    }
83

84
    process_readme_template(
85
        &workspace_dir,
×
86
        &workspace_template_path,
×
87
        &mut has_diffs,
×
88
        opts.clone(),
×
89
    );
90

91
    // Add workspace to the list of generated READMEs
UNCOV
92
    generated_crates.push("workspace".to_string());
×
93

94
    // Print a comma-separated list of all crates we generated READMEs for
UNCOV
95
    let execution_time = start.elapsed();
×
UNCOV
96
    if opts.check {
×
97
        info!(
×
98
            "📚 Checked READMEs for: {} (took {:?})",
×
99
            generated_crates.join(", ").blue(),
×
100
            execution_time
101
        );
UNCOV
102
    } else if has_diffs {
×
UNCOV
103
        info!(
×
UNCOV
104
            "📚 Generated READMEs for: {} (took {:?})",
×
105
            generated_crates.join(", ").blue(),
×
106
            execution_time
107
        );
108
    } else {
109
        info!(
×
110
            "✅ No changes to READMEs for: {} (took {:?})",
×
111
            generated_crates.join(", ").blue(),
×
112
            execution_time
113
        );
114
    }
115
    has_diffs
×
116
}
117

118
fn process_readme_template(
×
119
    crate_path: &Path,
120
    template_path: &Path,
121
    has_diffs: &mut bool,
122
    opts: Options,
123
) {
124
    // Get crate name from directory name
UNCOV
125
    let crate_name = crate_path
×
126
        .file_name()
127
        .unwrap()
128
        .to_string_lossy()
129
        .to_string();
130

131
    // Read the template
132
    let template_content = fs_err::read_to_string(template_path)
×
UNCOV
133
        .unwrap_or_else(|_| panic!("Failed to read template file: {:?}", template_path));
×
134

135
    // Combine header, template content, and footer
UNCOV
136
    let header = generate_header(&crate_name);
×
UNCOV
137
    let footer = generate_footer();
×
UNCOV
138
    let content = format!("{}\n{}\n{}", header, template_content, footer);
×
139

140
    // Save the rendered content to README.md
UNCOV
141
    let readme_path = crate_path.join("README.md");
×
UNCOV
142
    *has_diffs |= write_if_different(&readme_path, content.into_bytes(), opts.check);
×
143
}
144

145
// Define header and footer templates
UNCOV
146
fn generate_header(crate_name: &str) -> String {
×
UNCOV
147
    let template = include_str!("header.md");
×
148
    template.replace("{CRATE}", crate_name)
×
149
}
150

UNCOV
151
fn generate_footer() -> String {
×
UNCOV
152
    include_str!("footer.md").to_string()
×
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc