From 9a9b51ea0a533c414a8ef0387ae62c0e3439c572 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Mon, 20 Jul 2020 12:11:37 +0100
Subject: [PATCH] TEST: Test remove_ext, tweak imrm test

---
 tests/test_scripts/test_imrm.py       |  5 ++--
 tests/test_scripts/test_remove_ext.py | 38 +++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 tests/test_scripts/test_remove_ext.py

diff --git a/tests/test_scripts/test_imrm.py b/tests/test_scripts/test_imrm.py
index ba7ff1c8d..d6682400a 100644
--- a/tests/test_scripts/test_imrm.py
+++ b/tests/test_scripts/test_imrm.py
@@ -13,7 +13,7 @@ import fsl.scripts.imrm as imrm
 from tests import touch
 
 def test_imrm_usage():
-    assert imrm.main(['imrm']) != 0
+    assert imrm.main([]) != 0
 
 
 def test_imrm():
@@ -45,6 +45,7 @@ def test_imrm():
             print('command',  command)
             print('expected', expected)
 
-            imrm.main(('imrm ' + command).split())
+            ret = imrm.main(('imrm ' + command).split())
 
+            assert ret == 0
             assert sorted(os.listdir()) == sorted(expected.split())
diff --git a/tests/test_scripts/test_remove_ext.py b/tests/test_scripts/test_remove_ext.py
new file mode 100644
index 000000000..bb65a893a
--- /dev/null
+++ b/tests/test_scripts/test_remove_ext.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+#
+# test_remove_ext.py -
+#
+# Author: Paul McCarthy <pauldmccarthy@gmail.com>
+#
+
+
+import fsl.scripts.remove_ext as remove_ext
+
+from tests import CaptureStdout
+
+def test_usage():
+    assert remove_ext.main([]) != 0
+
+def test_remove_ext():
+    # (input, expected output)
+    tests = [
+        ('a',                 'a'),
+        ('a.nii',             'a'),
+        ('a.nii.gz',          'a'),
+        ('a.txt',             'a.txt'),
+        ('a.nii b.img c.hdr', 'a b c'),
+        ('a.nii b.img b.hdr', 'a b b'),
+        ('a b.img c.txt',     'a b c.txt'),
+        ('a.nii.gz b c.mnc',  'a b c'),
+    ]
+
+    for input, expected in tests:
+
+        cap = CaptureStdout()
+        with cap:
+            ret = remove_ext.main(input.split())
+
+        assert ret == 0
+
+        got = cap.stdout.split()
+        assert sorted(got) == sorted(expected.split())
-- 
GitLab