cahya_test/
lib.rs

1//use std::env::var("$CARGO_MANIFEST_DIR")
2use std::{env, fs};
3use std::path::Path;
4use log::debug;
5
6pub fn add(left: usize, right: usize) -> usize {
7    debug!("### ADD");
8    left + right
9}
10
11pub fn print_readme() -> String {
12    let path_to_crate= env!("CARGO_MANIFEST_DIR");
13    debug!("path_to_crate: {:?}", path_to_crate);
14
15
16    let mypath = Path::new(env!("CARGO_MANIFEST_DIR")).join("assets").join("README.md");
17    let contents = fs::read_to_string(mypath).
18        expect("Should have been able to read the file");
19    println!("Contents:\n{:?}", contents);
20
21
22    let manifest_dir = env::var("CARGO_MANIFEST_DIR");
23    //let manifest_dir = env::var_os("CARGO_MANIFEST_DIR");
24    //let version = env!("CARGO_PKG_VERSION");
25    println!("manifest_dir: {:?}", manifest_dir);
26    return "Hello".to_string();
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn it_works() {
35        let result = add(2, 2);
36        assert_eq!(result, 4);
37    }
38    #[test]
39    fn readme() {
40        let result = print_readme();
41        assert_eq!(result, "abc".to_string());
42    }
43}