From patchwork Mon Feb 25 11:07:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 1047674 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 447K142Dqpz9s6w for ; Mon, 25 Feb 2019 22:07:52 +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 447K136pyxzDqQw for ; Mon, 25 Feb 2019 22:07:51 +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) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 447K0z2nlJzDqLB for ; Mon, 25 Feb 2019 22:07:47 +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 447K0y4tvzz9s70; Mon, 25 Feb 2019 22:07:46 +1100 (AEDT) From: Michael Ellerman To: snowpatch@lists.ozlabs.org Date: Mon, 25 Feb 2019 22:07:44 +1100 Message-Id: <20190225110744.29246-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [snowpatch] [PATCH] 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 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index ec98bb4..00ef0ea 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -16,3 +16,39 @@ 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__"); + } +}