From 204852bf3d6c6159dfa25bd79ce4f014cde5d83b Mon Sep 17 00:00:00 2001 From: Shane St Savage Date: Fri, 12 Apr 2024 12:15:29 -0700 Subject: [PATCH] Make HashDigestTests portable by removing absolute prefix of test path Partially fixes #140 --- src/test/java/com/cohort/util/HashDigestTests.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/cohort/util/HashDigestTests.java b/src/test/java/com/cohort/util/HashDigestTests.java index f0c21ad0..dbf0a860 100644 --- a/src/test/java/com/cohort/util/HashDigestTests.java +++ b/src/test/java/com/cohort/util/HashDigestTests.java @@ -8,6 +8,11 @@ class HashDigestTests { void basicTest() throws Throwable { System.out.println("*** HashDigest.basicTest"); String tName = HashDigestTests.class.getResource("LICENSE.txt").getPath(); + String projectDir = File2.getCurrentDirectory(); + //remove projectDir prefix from absolute tName path to make tests portable + if (tName.startsWith(projectDir)) { + tName = tName.substring(projectDir.length()); + } Test.ensureEqual(HashDigest.doIt(new String[] { "type:MD5" }), "Neither password or filename was specified.\n" + HashDigest.usage, ""); Test.ensureEqual(HashDigest.doIt(new String[] { "password:myPassword", "type:MD-5" }), @@ -19,13 +24,13 @@ void basicTest() throws Throwable { Test.ensureEqual(HashDigest.doIt(new String[] { "password:myPassword", "type:SHA-256" }), "76549b827ec46e705fd03831813fa52172338f0dfcbd711ed44b81a96dac51c6", ""); Test.ensureEqual(HashDigest.doIt(new String[] { "filename:" + tName, "type:MD5" }), - "96e9b4d974b734874a66f433b276a41a", ""); + "327fbb2aa6c6297d4fdd5fdf4b14e289", ""); Test.ensureEqual(HashDigest.doIt(new String[] { "filename:" + tName, "type:SHA-256" }), - "f6afea3f5fa69c8e54b14b3fdb86a9aa261a423cea957c9c87b55b92441d56bb", ""); + "e376c88953b2d56b00783fed071f1875e8ed94230f4e14eee5bce8bd608de5e6", ""); Test.ensureEqual(HashDigest.doIt(new String[] { "filename:" + tName, "type:SHA-256", "-file" }), "Created " + tName + ".sha256", ""); Test.ensureEqual(File2.readFromFileUtf8(tName + ".sha256")[1], - "f6afea3f5fa69c8e54b14b3fdb86a9aa261a423cea957c9c87b55b92441d56bb LICENSE.txt\n", ""); + "e376c88953b2d56b00783fed071f1875e8ed94230f4e14eee5bce8bd608de5e6 LICENSE.txt\n", ""); File2.delete(tName + ".sha256"); } }