1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
use git_testament::{git_testament, git_testament_macros, render_testament};
git_testament!(TESTAMENT);
git_testament_macros!(version);
mod inner {
use git_testament::git_testament;
git_testament!(pub INNER);
}
#[test]
fn it_works() {
println!("Testament: {TESTAMENT}");
println!("Inner: {}", inner::INNER);
}
//testament macro is not guaranteed to be indentical to testament's Display in `no_std`
#[cfg(feature = "alloc")]
#[test]
fn macros_work() {
assert_eq!(render_testament!(TESTAMENT), version_testament!());
}
mod testutils;
#[test]
fn verify_builds_ok() {
let test = testutils::prep_test("no-git");
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_contains("1.0.0");
}
#[test]
fn verify_no_commit() {
let test = testutils::prep_test("no-commit");
assert!(test.basic_git_init());
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_contains("uncommitted");
}
#[test]
fn verify_no_changes_no_tags() {
let test = testutils::prep_test("no-changes");
assert!(test.basic_git_init());
assert!(test.run_cmd("cargo", &["check"]));
assert!(test.run_cmd("git", &["add", "."]));
assert!(test.run_cmd("git", &["commit", "-m", "first"]));
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_parts("unknown", 0, "TODO", None);
}
#[test]
fn verify_no_changes_with_a_tag() {
let test = testutils::prep_test("no-changes-with-tag");
assert!(test.basic_git_init());
assert!(test.run_cmd("cargo", &["check"]));
assert!(test.run_cmd("git", &["add", "."]));
assert!(test.run_cmd("git", &["commit", "-m", "first"]));
assert!(test.run_cmd("git", &["tag", "-m", "1.0.0", "1.0.0"]));
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_parts("1.0.0", 0, "TODO", None);
}
#[test]
fn verify_dirty_changes_with_a_tag() {
let test = testutils::prep_test("dirty-with-tag");
assert!(test.basic_git_init());
assert!(test.run_cmd("cargo", &["check"]));
assert!(test.run_cmd("git", &["add", "."]));
assert!(test.run_cmd("git", &["commit", "-m", "first"]));
assert!(test.run_cmd("git", &["tag", "-m", "1.0.0", "1.0.0"]));
test.dirty_code();
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_parts("1.0.0", 0, "TODO", Some(1));
}
#[test]
fn verify_another_commit_with_a_tag() {
let test = testutils::prep_test("tag-plus-commit");
assert!(test.basic_git_init());
assert!(test.run_cmd("cargo", &["check"]));
assert!(test.run_cmd("git", &["add", "."]));
assert!(test.run_cmd("git", &["commit", "-m", "first"]));
assert!(test.run_cmd("git", &["tag", "-m", "1.0.0", "1.0.0"]));
test.dirty_code();
assert!(test.run_cmd("git", &["add", "."]));
assert!(test.run_cmd("git", &["commit", "-m", "second"]));
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_parts("1.0.0", 1, "TODO", None);
}
#[test]
fn verify_trusted_branch() {
let test = testutils::prep_test("trusted-branch");
assert!(test.basic_git_init());
assert!(test.run_cmd("cargo", &["check"]));
assert!(test.run_cmd("git", &["add", "."]));
assert!(test.run_cmd("git", &["commit", "-m", "first"]));
assert!(test.run_cmd("git", &["tag", "-m", "1.0.0", "1.0.0"]));
assert!(test.run_cmd("git", &["checkout", "-b", "aaaa"]));
test.dirty_code();
assert!(test.run_cmd("git", &["add", "."]));
assert!(test.run_cmd("git", &["commit", "-m", "second"]));
assert!(test.run_cmd("git", &["checkout", "-b", "trusted"]));
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_parts("1.0.0", 0, "TODO", None);
}
#[test]
fn verify_source_date_epoch_no_repo() {
let mut test = testutils::prep_test("source-date-epoch-norepo");
test.setenv("SOURCE_DATE_EPOCH", "324086400");
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_contains("1.0.0");
test.assert_manifest_contains("1980-04-09");
}
#[test]
fn verify_source_date_epoch_no_commit() {
let mut test = testutils::prep_test("source-date-epoch-nocommit");
assert!(test.basic_git_init());
test.setenv("SOURCE_DATE_EPOCH", "324086400");
assert!(test.run_cmd("cargo", &["build"]));
test.assert_manifest_contains("1.0.0");
test.assert_manifest_contains("1980-04-09");
}
|