From patchwork Mon Feb 25 11:12:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 1047679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 447K933MFPz9s6w for ; Mon, 25 Feb 2019 22:14:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 447K932S1lzDqTy for ; Mon, 25 Feb 2019 22:14:47 +1100 (AEDT) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 447K6x3y3ZzDq5k for ; Mon, 25 Feb 2019 22:12:57 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Received: by ozlabs.org (Postfix, from userid 1034) id 447K6x3BbXz9s9y; Mon, 25 Feb 2019 22:12:57 +1100 (AEDT) From: Michael Ellerman To: snowpatch@lists.ozlabs.org Date: Mon, 25 Feb 2019 22:12:54 +1100 Message-Id: <20190225111254.31152-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [snowpatch] [PATCH v2] utils: Add tests of sanitise_path() X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Signed-off-by: Michael Ellerman --- src/utils.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) v2: rustfmt it, doh! diff --git a/src/utils.rs b/src/utils.rs index ec98bb4..6650884 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -16,3 +16,42 @@ pub fn sanitise_path(path: &str) -> String { path.replace(|c: char| !c.is_alphanumeric(), "_") } + +#[cfg(test)] +mod test { + use super::sanitise_path; + + #[test] + fn test_dereference() { + assert_eq!( + sanitise_path("powerpc/64: Simplify __secondary_start paca->kstack handling"), + "powerpc_64__Simplify___secondary_start_paca__kstack_handling" + ); + } + + #[test] + fn test_semi_colon() { + assert_eq!( + sanitise_path("powerpc: hwrng; fix missing of_node_put()"), + "powerpc__hwrng__fix_missing_of_node_put__" + ); + } + + #[test] + fn test_null() { + assert_eq!( + sanitise_path("powerpc: There is a \0 in this subject"), + "powerpc__There_is_a___in_this_subject" + ); + } + + #[test] + fn test_paths() { + assert_eq!(sanitise_path("cat /etc/passwd"), "cat__etc_passwd"); + } + + #[test] + fn test_options() { + assert_eq!(sanitise_path("rm -rf /"), "rm__rf__"); + } +}