diff --git a/rush00 b/rush00 index 8d934bb..faac610 160000 --- a/rush00 +++ b/rush00 @@ -1 +1 @@ -Subproject commit 8d934bb6e246a7ff47fec231088330acfad29331 +Subproject commit faac610dd631891998a3c3b7219238c8b20f82f9 diff --git a/unit-tests/helper.py b/unit-tests/helper.py index 10bc4a6..f28fdd3 100755 --- a/unit-tests/helper.py +++ b/unit-tests/helper.py @@ -27,23 +27,17 @@ def run_command(cmd): # count of things that didn't go so well failed_count = 0 -def execcom(command): - try: - exitcode, out, err = run_command(command) - except: - print("The program couldn't execute the command.\n" + - "Here's the command for debugging purposes: ") - print(str(command)) - exit(1) - return exitcode, out, err - def test_command(command, expected, check_std_err = 1): global failed_count - exitcode, out, err = execcom(command) + exitcode, out, err = 0, 0, "" + try: + exitcode, out, err = run_command(command) + except: + print("") if (expected == out): # if (len(command) > 100): - # command = command[:100] + "..."; + # command = command[:100] + "..." print("passed: " + str(command)) else: print("FAILED: " + str(command)) @@ -59,7 +53,7 @@ def test_boolean(boolean, string): print("passed: " + str(string)) else: print("FAILED: " + str(string)) - failed_count += 1; + failed_count += 1 def print_final_results(): print("") diff --git a/unit-tests/test_d01.py b/unit-tests/test_d01.py index d699315..36be069 100755 --- a/unit-tests/test_d01.py +++ b/unit-tests/test_d01.py @@ -2,9 +2,8 @@ from helper import * -# day_location = "/Users/vbrazas/projects/php_piscine/d01/" -day_location = "/Users/vbrazas/.Trash/ang/" -helpers = "/Users/vbrazas/projects/php_piscine/unit-tests/helpers_d01/" +day_location = "/Users/vbrazas/projects/archive/php_piscine/d01/" +helpers = "/Users/vbrazas/projects/archive/php_piscine/unit-tests/helpers_d01/" # START OF TESTS START OF TESTS START OF TESTS START OF TESTS @@ -246,4 +245,4 @@ # Enter a number: ^D""") # print("") -print_final_results(); +print_final_results() diff --git a/unit-tests/test_d02.py b/unit-tests/test_d02.py index 2678833..705f1be 100755 --- a/unit-tests/test_d02.py +++ b/unit-tests/test_d02.py @@ -79,7 +79,7 @@ print("") # ex03 -exitcode, out, err = execcom('who') +exitcode, out, err = run_command('who') test_command(day_location + "/ex03/who.php", out) print("") @@ -153,4 +153,4 @@ # END OF TESTS END OF TESTS END OF TESTS END OF TESTS END OF TESTS -print_final_results(); +print_final_results() diff --git a/unit-tests/test_d03.py b/unit-tests/test_d03.py index 0ac0e1a..b895c70 100755 --- a/unit-tests/test_d03.py +++ b/unit-tests/test_d03.py @@ -2,13 +2,13 @@ from helper import * -# for expanding the ~ in filenames; checking if a file exists +# for expanding the ~ in filenames checking if a file exists # import os # from os.path import expanduser # from os.path import isfile # from os.path import isdir -day_location = "http://localhost:8100/d03" +day_location = "http://localhost:8100/deleteme" # day_location = "http://localhost:8100/php_piscine/d03" # START OF TESTS START OF TESTS START OF TESTS START OF TESTS @@ -153,10 +153,10 @@ def lynx_tests(): print("\nTests for ex05:") def test_ex05(): command = "curl --head " + day_location + "/ex05/read_img.php" - exitcode, out, err = run_command(command); + exitcode, out, err = run_command(command) test_boolean("Content-Type: image/png" in out, "content type test") command = "curl " + day_location + "/ex05/read_img.php" - exitcode, out, err = run_command(command); + exitcode, out, err = run_command(command) test_boolean(out == open((day_location + "/img/42.png"), 'r').read(), "image content test") # test_ex05() @@ -173,9 +173,9 @@ def test_ex05(): test_boolean("That area is accessible for members only" in out, "actual body part for unauthorized page") exitcode, out, err = run_command("curl --user zaz:jaimelespetitsponeys " + day_location + "/ex06/members_only.php") test_boolean("\nHello Zaz
" in out, "hello zaz") -test_boolean("" in out, "second image") # END OF TESTS END OF TESTS END OF TESTS END OF TESTS END OF TESTS -print_final_results(); +print_final_results() diff --git a/unit-tests/test_d04.py b/unit-tests/test_d04.py index 0e34392..def915e 100755 --- a/unit-tests/test_d04.py +++ b/unit-tests/test_d04.py @@ -2,14 +2,14 @@ from helper import * -# for expanding the ~ in filenames; checking if a file exists +# for expanding the ~ in filenames checking if a file exists import os from os.path import expanduser from os.path import isfile from os.path import isdir -day_on_server_location = "http://localhost:8100/php_piscine/d04" -location_of_private = "/Users/vbrazas/http/MyWebSite/php_piscine/d04/private" +day_on_server_location = "http://localhost:8100/d04" +location_of_private = "/Users/vbrazas/http/MyWebSite/d04/private" # # START OF TESTS START OF TESTS START OF TESTS START OF TESTS @@ -19,15 +19,15 @@ # exit(1) # print("Copying git repo to the correct location...") -# exitcode, out, err = execcom("rsync -rv --exclude=.git " + day_on_server_location + " " + expanduser("~/http/MyWebSite/d04")) +# exitcode, out, err = run_command("rsync -rv --exclude=.git " + day_on_server_location + " " + expanduser("~/http/MyWebSite/d04")) # if (len(err) > 0 and "identical" not in err): # print("Failed to copy files!") # print(err) # exit(1) -# execcom("mkdir " + expanduser("~/mamp/apps/j04/conf")) -# execcom("cp " + day_on_server_location + "ex00/httpd-app.conf " + expanduser("~/mamp/apps/j04/conf")) -# execcom("cp " + day_on_server_location + "ex00/httpd-vhosts.conf " + expanduser("~/mamp/apps/j04/conf")) -# execcom("cp " + expanduser("~/mamp/apps/demo/conf/httpd-prefix.conf") + " " + expanduser("~/mamp/apps/j04/conf")) +# run_command("mkdir " + expanduser("~/mamp/apps/j04/conf")) +# run_command("cp " + day_on_server_location + "ex00/httpd-app.conf " + expanduser("~/mamp/apps/j04/conf")) +# run_command("cp " + day_on_server_location + "ex00/httpd-vhosts.conf " + expanduser("~/mamp/apps/j04/conf")) +# run_command("cp " + expanduser("~/mamp/apps/demo/conf/httpd-prefix.conf") + " " + expanduser("~/mamp/apps/j04/conf")) # print("") @@ -41,65 +41,65 @@ # ex00 print("\nTests for ex00:") -execcom("rm -f cook.txt") +run_command("rm -f cook.txt") -exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'") +exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'") test_boolean('name="login"' in out, "login named correctly") test_boolean(("value" not in out) or ('value=""' in out), "login set correctly") -exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'") +exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'") test_boolean('name="passwd"' in out, "passwd named correctly") test_boolean(("value" not in out) or ('value=""' in out), "passwd set correctly") -exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'") +exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'") test_boolean('name="submit"' in out, "submit named correctly") test_boolean(("value" not in out) or ('value="OK"' in out), "submit set correctly") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'login'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'login'") test_boolean('name="login"' in out, "login named correctly after no ok") test_boolean(("value" not in out) or ('value=""' in out), "login set correctly after no ok") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'") test_boolean('name="passwd"' in out, "passwd named correctly after no ok") test_boolean(("value" not in out) or ('value=""' in out), "passwd set correctly after no ok") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'") test_boolean('name="submit"' in out, "submit named correctly after no ok") test_boolean(("value" not in out) or ('value="OK"' in out), "submit set correctly after no ok") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone&submit=OK' | grep 'login'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone&submit=OK' | grep 'login'") test_boolean('name="login"' in out, "login named correctly after ok") test_boolean('value="sb"' in out, "login set correctly after ok") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'") test_boolean('name="passwd"' in out, "passwd named correctly after ok") test_boolean('value="beeone"' in out, "passwd set correctly after ok") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'") test_boolean('name="submit"' in out, "submit named correctly after ok") test_boolean('value="OK"' in out, "submit set correctly after ok") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'") test_boolean('name="login"' in out, "login named correctly after not passing stuff in url") test_boolean('value="sb"' in out, "login set correctly after not passing stuff in url") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'") test_boolean('name="passwd"' in out, "passwd named correctly after not passing stuff in url") test_boolean('value="beeone"' in out, "passwd set correctly after not passing stuff in url") -exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'") +exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'") test_boolean('name="submit"' in out, "submit named correctly after not passing stuff in url") test_boolean('value="OK"' in out, "submit set correctly after not passing stuff in url") -exitcode, out, err = execcom("curl -v '" + day_on_server_location + "/ex00/index.php' | grep 'login'") +exitcode, out, err = run_command("curl -v '" + day_on_server_location + "/ex00/index.php' | grep 'login'") test_boolean('name="login"' in out, "login named correctly after removing cookie file") test_boolean(("value" not in out) or ('value=""' in out), "login set correctly after removing cookie file") -exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'") +exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'") test_boolean('name="passwd"' in out, "passwd named correctly after removing cookie file") test_boolean(("value" not in out) or ('value=""' in out), "passwd set correctly after removing cookie file") -exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'") +exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'") test_boolean('name="submit"' in out, "submit named correctly after removing cookie file") test_boolean(("value" not in out) or ('value="OK"' in out), "submit set correctly after removing cookie file") -execcom("rm -f cook.txt") +run_command("rm -f cook.txt") print("") # ex01 print("Tests for ex01:") -execcom("rm -rf " + expanduser(location_of_private)) +run_command("rm -rf " + expanduser(location_of_private)) test_command("curl -d login=toto1 -d passwd=titi1 -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "OK\n", 0) password_file = expanduser(location_of_private + "/passwd") test_boolean('a:1:{' == get_file_contents(password_file)[:5] @@ -110,14 +110,14 @@ test_command("curl -d login=toto1 -d passwd=titi1 -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "ERROR\n", 0) test_command("curl -d login=toto1 -d passwd=titi1 -d submit=OKK '" + day_on_server_location + "/ex01/create.php'", "ERROR\n", 0) test_command("curl -d login=login -d passwd=password '" + day_on_server_location + "/ex01/create.php'", "ERROR\n", 0) -exitcode, out, err = execcom("curl -v '" + day_on_server_location + "/ex01/index.html'") +exitcode, out, err = run_command("curl -v '" + day_on_server_location + "/ex01/index.html'") test_boolean('method="POST"' in out or 'method="post"' in out, "correct method") -execcom("rm -rf " + expanduser(location_of_private)) +run_command("rm -rf " + expanduser(location_of_private)) print("") # ex02 print("Tests for ex02:") -execcom("rm -rf " + expanduser(location_of_private)) +run_command("rm -rf " + expanduser(location_of_private)) test_command("curl -d login=x -d passwd=21 -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "OK\n", 0) password_file = location_of_private + "/passwd" test_boolean('a:1:{' == get_file_contents(location_of_private + "/passwd")[:5] @@ -130,29 +130,29 @@ test_command("curl -d login=x -d oldpw=21 -d newpw=42 -d submit=OK '" + day_on_server_location + "/ex02/modif.php'", "ERROR\n", 0) # wrong password test_command("curl -d login=x -d oldpw=42 -d newpw= -d submit=OK '" + day_on_server_location + "/ex02/modif.php'", "ERROR\n", 0) # blank new password -exitcode, out, err = execcom("curl -v '" + day_on_server_location + "/ex02/index.html'") +exitcode, out, err = run_command("curl -v '" + day_on_server_location + "/ex02/index.html'") test_boolean('method="POST"' in out or 'method="post"' in out, "correct method") -execcom("rm -rf " + expanduser(location_of_private)) +run_command("rm -rf " + expanduser(location_of_private)) print("") # ex03 print("Tests for ex03:") -execcom("rm -rf " + expanduser(location_of_private)) +run_command("rm -rf " + expanduser(location_of_private)) test_command("curl -d login=toto -d passwd=titi -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "OK\n", 0) password_file = location_of_private + "/passwd" test_boolean('a:1:{' == get_file_contents(location_of_private + "/passwd")[:5] , "begin part of serialized file (" + password_file + ")") test_command("curl '" + day_on_server_location + "/ex03/login.php?login=toto&passwd=titi'", "OK\n", 0) # check login.php: correct -execcom("rm -rf " + expanduser(location_of_private)) -execcom("curl -d login=toto -d passwd=titi -d submit=OK '" + day_on_server_location + "/ex01/create.php'") +run_command("rm -rf " + expanduser(location_of_private)) +run_command("curl -d login=toto -d passwd=titi -d submit=OK '" + day_on_server_location + "/ex01/create.php'") test_command("curl -c cook.txt '" + day_on_server_location + "/ex03/login.php?login=toto&passwd=titi'", "OK\n", 0) test_command("curl -b cook.txt '" + day_on_server_location + "/ex03/whoami.php'", "toto\n", 0) test_command("curl -b cook.txt '" + day_on_server_location + "/ex03/logout.php'", "", 0) test_command("curl -b cook.txt '" + day_on_server_location + "/ex03/whoami.php'", "ERROR\n", 0) -execcom("rm -f cook.txt") +run_command("rm -f cook.txt") # END OF TESTS END OF TESTS END OF TESTS END OF TESTS END OF TESTS -print_final_results(); +print_final_results() diff --git a/unit-tests/test_d06.zsh b/unit-tests/test_d06.zsh index 9f00ea5..e660ea3 100755 --- a/unit-tests/test_d06.zsh +++ b/unit-tests/test_d06.zsh @@ -1,10 +1,9 @@ #!/bin/zsh - #### ▼▼▼▼ Please insert global path to your day and resources folders below ▼▼▼▼ #### -WORK_D='/Users/vbrazas/.Trash/d06/' -# WORK_D='/Users/vbrazas/projects/php_piscine/d06/' -RES_D='/Users/vbrazas/projects/php_piscine/resources/d06/' +WORK_D="$HOME/.Trash/d06/" +# WORK_D="$HOME/projects/php_piscine/d06/" +RES_D="$HOME/projects/php_piscine/resources/d06/" # To use Single_checker© you need to be in the folder of the direct exersize @@ -24,6 +23,7 @@ if [[ $1 ]]; then sleep 2 less diffs.out else + rm -f main.out my.out diffs.out fi exit 1; diff --git a/unit-tests/test_d07.py b/unit-tests/test_d07.py index 3b5b074..deccc31 100755 --- a/unit-tests/test_d07.py +++ b/unit-tests/test_d07.py @@ -2,12 +2,12 @@ from helper import * -# for expanding the ~ in filenames; checking if a file exists +# for expanding the ~ in filenames checking if a file exists # expanduser, isfile, isdir, chdir import os -day_location = "/Users/vbrazas/projects/php_piscine/d07/" -resources = "resources_d07/" +day_location = "/Users/vbrazas/.Trash/vbrazas2/" +resources = "/Users/vbrazas/projects/php_piscine/unit-tests/resources_d07/" tester_dir = os.getcwd() # START OF TESTS START OF TESTS START OF TESTS START OF TESTS @@ -37,7 +37,7 @@ Fighter.class.php UnholyFactory.class.php """ -test_boolean((after_grep == answer[:len(after_grep)]), "correct files"); +test_boolean((after_grep == answer[:len(after_grep)]), "correct files") # ex00