diff --git a/makedocker b/makedocker index 049c51b..9424fbb 100755 --- a/makedocker +++ b/makedocker @@ -7,7 +7,7 @@ then echo "In the first case, the name of the study is the same as the name of the .graphml" echo "In either case, source files come from the same path as the .graphml" echo "The equivalent mkconcore.py is displayed" - exit + exit 1 fi graphml=$1 if [ -e $graphml ] @@ -20,7 +20,7 @@ else sourcedir=$(dirname "$graphml") else echo "$graphml does not exist" - exit + exit 1 fi fi if [ $# = 1 ] @@ -33,6 +33,7 @@ if [ -e $studydir ] then echo "cannot make $studydir because one already exists with that name" echo "either do ./destroy $studydir, or choose a unique name as 2nd arg" + exit 1 else echo "python3 mkconcore.py $graphml $sourcedir $studydir docker" python3 mkconcore.py $graphml $sourcedir $studydir docker diff --git a/makestudy b/makestudy index cc01750..f3ec583 100755 --- a/makestudy +++ b/makestudy @@ -7,7 +7,7 @@ if [ "$#" -eq 0 ]; then echo "In the first case, the name of the study is the same as the name of the .graphml" echo "In either case, source files come from the same path as the .graphml" echo "The equivalent mkconcore.py is displayed" - exit + exit 1 fi graphml="$1" @@ -20,7 +20,7 @@ else sourcedir="$(dirname "$graphml")" else echo "$graphml does not exist" - exit + exit 1 fi fi @@ -34,7 +34,7 @@ fi if [ -e "$studydir" ]; then echo "Cannot make $studydir because one already exists with that name" echo "Either do ./destroy $studydir, or choose a unique name as 2nd arg" - exit + exit 1 else if command -v osascript >/dev/null; then echo "python3 mkconcore.py \"$graphml\" \"$sourcedir\" \"$studydir\" macos" diff --git a/tests/test_makestudy_exit_codes.py b/tests/test_makestudy_exit_codes.py new file mode 100644 index 0000000..6d44e53 --- /dev/null +++ b/tests/test_makestudy_exit_codes.py @@ -0,0 +1,50 @@ +"""makestudy and makedocker must exit non-zero when they fail. + +The FRI server (fri/server/main.py) runs them with subprocess.check_output and +only reports an error on a non-zero exit code, so exiting 0 after a failure +made the editor report "Directory successfully created". +""" + +import subprocess +import sys +from pathlib import Path + +import pytest + +REPO = Path(__file__).resolve().parents[1] +SCRIPTS = ["makestudy", "makedocker"] + +pytestmark = pytest.mark.skipif( + sys.platform == "win32", reason="makestudy and makedocker are bash scripts" +) + + +def _run(script, *args): + return subprocess.run( + ["bash", str(REPO / script), *args], + cwd=REPO, + capture_output=True, + text=True, + ) + + +@pytest.mark.parametrize("script", SCRIPTS) +def test_no_arguments_exits_nonzero(script): + result = _run(script) + assert result.returncode != 0 + assert "Make a concore study" in result.stdout + + +@pytest.mark.parametrize("script", SCRIPTS) +def test_missing_graphml_exits_nonzero(script): + result = _run(script, "demo/does_not_exist") + assert result.returncode != 0 + assert "does not exist" in result.stdout + + +@pytest.mark.parametrize("script", SCRIPTS) +def test_existing_study_dir_exits_nonzero(script, tmp_path): + result = _run(script, "demo/sample.graphml", str(tmp_path)) + assert result.returncode != 0 + assert "already exists" in result.stdout + assert list(tmp_path.iterdir()) == []