This article lists some example solutions. For each of these solutions, an SCT is included, as well as some example student submissions that would pass and fail. In all of these, a submission that is identical to the solution will evidently pass.
These SCT examples are not golden bullets that are perfect for your situation. Depending on the exercise, you may want to focus on certain parts of a statement, or be more accepting for different alternative answers.
Checking the current directory¶
# solution command cd test
# sct Ex().has_cwd('/home/repl/test')
# solution command ls
# sct Ex().check_correct( has_cwd('/home/repl') has_expr_output() )
Checking whether a directory exists¶
# solution command mdkir /home/repl/test
# sct Ex().has_dir('/home/repl/test')
Checking command output¶
# solution command echo 'this is a printout!'
# sct Ex().has_output(r'this\\s+is\\s+a\\s+print\\s*out')
# Submissions that would pass: echo 'this is a print out' test='this is a printout!' && echo $test # Submissions that would fail: echo 'this is a wrong printout'
Checking contents of a file¶
# solution command echo hello > test.txt
# sct Ex().check_file('/home/repl/test.txt').multi( # check that file contains hello or hi has_code(r'hello|hi'), # check that file does not contain goodbye check_not(has_code('goodbye'), incorrect_msg="meaningful error message") )
Git: check branch¶
# solution command (while in the test git repo) git checkout make-change
Ex().multi( has_cwd('/home/repl/test'), has_expr_output(expr='git rev-parse --abbrev-ref HEAD | grep make-change', output='make-change', strict=True, incorrect_msg=meaningful message") )
Git: check that file was staged¶
# solution command (while in the test git repo) git add test.txt
# sct Ex().multi( has_cwd('/home/repl/test') has_expr_output(expr="git diff --name-only --staged | grep test.txt", output="test.txt", strict=True, incorrect_msg="meaningful message") )