diff --git a/.github/workflow/build_and_test.yml b/.github/workflow/build_and_test.yml deleted file mode 100644 index 18812f0..0000000 --- a/.github/workflow/build_and_test.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Build and Run Tests - -on: - push: {} - workflow_dispatch: {} - -jobs: - build: - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - name: Checkout - uses: actions/checkout@v4 - - uses: xu-cheng/texlive-action@v2 - with: - scheme: full # Consider changing to 'basic' or 'medium' if possible - run: | - apk add make - apk add g++ - apk add zip - make script zip - - uses: actions/upload-artifact@v4 - with: - name: PDF_Test - path: vorkurs.pdf - - check-links: - runs-on: ubuntu-latest - needs: build - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Download compiled PDF - uses: actions/download-artifact@v4 - with: - name: PDF_Test - path: . - - - name: Install pdfgrep - run: sudo apt-get update && sudo apt-get install -y pdfgrep - - - name: Extract and Check URLs - run: | - urls=$(pdfgrep -o -P 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' vorkurs.pdf | sort -u) - error_count=0 - - for url in $urls; do - echo "Checking URL: $url" - - if [[ ! "$url" =~ ^https:// ]]; then - echo "ERROR: URL is not HTTPS: $url" - error_count=$((error_count + 1)) - continue - fi - - if ! curl -Isf --fail-early --connect-timeout 10 "$url" > /dev/null 2>&1; then - curl_error=$(curl -Isf --fail-early --connect-timeout 10 "$url" 2>&1 > /dev/null) - if [[ $curl_error == *"Failed to connect"* ]]; then - echo "ERROR: Connection failed: $url" - elif [[ $curl_error == *"Could not resolve host"* ]]; then - echo "ERROR: DNS resolution failed: $url" - elif [[ $curl_error == *"SSL certificate problem"* ]]; then - echo "ERROR: Initial SSL certificate problem: $url" - else - echo "ERROR: Failed to access: $url (curl error: $curl_error)" - fi - if ! openssl s_client -connect "$(echo "$url" | sed 's/https\?:\/\///' | cut -d/ -f1):443" -servername "$(echo "$url" | sed 's/https\?:\/\///' | cut -d/ -f1)" 2>/dev/null CERTIFICATE ERROR DETECTED!" - fi - - error_count=$((error_count + 1)) - fi - done - - if [ "$error_count" -gt 0 ]; then - echo "::error::Found $error_count broken or insecure links!" - exit 1 - fi - shell: bash diff --git a/.github/workflows/test_scripts/check_compilability.py b/.github/workflows/test_scripts/check_compilability.py index 4bec112..a0476eb 100644 --- a/.github/workflows/test_scripts/check_compilability.py +++ b/.github/workflows/test_scripts/check_compilability.py @@ -2,8 +2,7 @@ import subprocess # Thats where our cpps are currently -BASE_PATH = "vorkurs/" - +BASE_PATH = "files/" def find_all_cpp_files(findWorking): vorkurs_path = pathlib.Path(BASE_PATH) @@ -18,19 +17,23 @@ def find_all_cpp_files(findWorking): def test_single_cpp_file(file_path, shouldCompile): - compile_status = subprocess.getoutput(f"g++ {file_path}") + compile_status = subprocess.getoutput(f"g++ {file_path} -w") - if (compile_status != "" and shouldCompile) or ( - compile_status == "" and not shouldCompile - ): + if compile_status != "" and shouldCompile: print("\n" + 20 * "=") print(f"Error in file {file_path}:\n") print(compile_status) print(20 * "=" + "\n") + return False + elif compile_status == "" and not shouldCompile: + print("\n" + 20 * "=") + print(f"File {file_path} compiles, but should be broken") + print("\n" + 20 * "=") - return True + return False + return True def main(): error_count_working = 0 @@ -50,12 +53,13 @@ def main(): print( f"::error::Found {error_count_working} non compiling files which should compile" ) - exit(1) - + if error_count_broken > 0: print( - f"::error:Found {error_count_broken} files that should be broken but compile" + f"::error::Found {error_count_broken} files that should be broken but compile" ) + + if error_count_broken > 0 or error_count_working > 0: exit(1) exit(0) diff --git a/Makefile b/Makefile index cfdb077..3e9f9e4 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,11 @@ dir: files/* @echo "Dateien kopieren…" @cp files/helloworld.cpp vorkurs/lektion01/. > /dev/null @cp files/helloyou.cpp vorkurs/lektion03/. > /dev/null - @cp files/fehler1.cpp vorkurs/lektion04/. > /dev/null - @cp files/fehler2.cpp vorkurs/lektion04/. > /dev/null - @cp files/fehler3.cpp vorkurs/lektion04/. > /dev/null - @cp files/fehler4.cpp vorkurs/lektion04/. > /dev/null - @cp files/fehler5.cpp vorkurs/lektion04/. > /dev/null + @cp files/noImport_broken.cpp vorkurs/lektion04/. > /dev/null + @cp files/noSemicolon2_broken.cpp vorkurs/lektion04/. > /dev/null + @cp files/noBracket_broken.cpp vorkurs/lektion04/. > /dev/null + @cp files/wrongDirection_broken.cpp vorkurs/lektion04/. > /dev/null + @cp files/noSemicolon2_broken.cpp vorkurs/lektion04/. > /dev/null @cp files/variablen.cpp vorkurs/lektion05/. > /dev/null @cp files/arith1.cpp vorkurs/lektion07/. > /dev/null @cp files/arith2.cpp vorkurs/lektion07/. > /dev/null diff --git a/files/array.cpp b/files/array.cpp index e69de29..0437c02 100644 --- a/files/array.cpp +++ b/files/array.cpp @@ -0,0 +1,18 @@ +#include + +int main() { + // Hier initialisieren wir das Array + int numbers[5] = {1, 4, 3, 9, 100}; + + // Wir zählen ab 0, das 5. Element hat also den Index 4 + int letzteZahl = numbers[4]; + + // So könnte man das Array in der Konsole ausgeben + std::cout << "Das Array beinhaltet die Zahlen" << std::endl; + + for (int n = 0; n < 5; n++) { + std::cout << numbers[n] << " "; + } + + return 0; +} diff --git a/files/fehler3.cpp b/files/noBracket_broken.cpp similarity index 100% rename from files/fehler3.cpp rename to files/noBracket_broken.cpp diff --git a/files/fehler1.cpp b/files/noImport_broken.cpp similarity index 100% rename from files/fehler1.cpp rename to files/noImport_broken.cpp diff --git a/files/fehler5.cpp b/files/noSemicolon2_broken.cpp similarity index 100% rename from files/fehler5.cpp rename to files/noSemicolon2_broken.cpp diff --git a/files/fehler2.cpp b/files/noSemicolon_broken.cpp similarity index 100% rename from files/fehler2.cpp rename to files/noSemicolon_broken.cpp diff --git a/files/fehler4.cpp b/files/wrongDirection_broken.cpp similarity index 100% rename from files/fehler4.cpp rename to files/wrongDirection_broken.cpp diff --git a/lektionen/errors_warnings.tex b/lektionen/errors_warnings.tex index 2519e8b..22a95ff 100644 --- a/lektionen/errors_warnings.tex +++ b/lektionen/errors_warnings.tex @@ -18,19 +18,22 @@ Nehmen wir z.B. mal folgendes Programm: -\inputcpp{fehler1.cpp} +\inputcpp{noImport\string_broken.cpp} Wenn wir versuchen, dieses zu kompilieren, gibt uns \texttt{g++} folgendes aus: -\begin{textcode*}{label=g++ -o fehler1 fehler1.cpp} - fehler1.cpp: In function 'int main()': - fehler1.cpp:2:5: error: 'cout' is not a member of 'std' - fehler1.cpp:2:35: error: 'endl' is not a member of 'std' +\begin{textcode*}{label=g++ -o fehler1 noImport\_broken.cpp} + noImport\_broken.cpp: In function 'int main()': + noImport\_broken.cpp:2:5: error: 'cout' is not a member of 'std' + noImport\_broken.cpp:2:35: error: 'endl' is not a member of 'std' \end{textcode*} +Je nach Compiler und Betriebssystem kann die Nachricht abweichen, im generellen ist der Fehler +aber immer auf das \texttt{std} bzw \texttt{cout} und \texttt{endl} zurückzuführen. + Wenn wir diese Fehlermeldung verstehen wollen, fangen wir immer ganz oben an, egal wie viel Text uns der Compiler ausspucken mag. In diesem Fall sagt uns die -erste Zeile, in welcher Datei (\texttt{fehler1.cpp}) der Fehler aufgetreten ist +erste Zeile, in welcher Datei (\texttt{noImport\string_broken.cpp}) der Fehler aufgetreten ist und in welcher Funktion (\texttt{int main()}). Die beiden Zeilen danach sind sogar noch spezifischer: Sie enthalten zu Beginn den Dateinamen, dann einen Doppelpunkt, gefolgt von einer Zeilennummer, gefolgt von einer @@ -50,14 +53,14 @@ Der nächste sehr häufig vorkommende Fehler ist subtiler: -\inputcpp{fehler2.cpp} +\inputcpp{noSemicolon\string_broken.cpp} Wenn wir versuchen, dies zu kompilieren, bekommen wir vom Compiler entgegengespuckt: -\begin{textcode*}{label=g++ -o fehler2 fehler2.cpp} - fehler2.cpp: In function 'int main()': - fehler2.cpp:5:1: error: expected ';' before '}' token +\begin{textcode*}{label=g++ -o fehler2 noSemicolon\_broken.cpp} + noSemicolon\_broken.cpp: In function 'int main()': + noSemicolon\_broken.cpp:5:1: error: expected ';' before '\}' token \end{textcode*} Wiederum sagt uns die erste Zeile, in welcher Datei und Funktion der Fehler @@ -88,8 +91,8 @@ korrekt arbeitet (schaut euch ggf. die bisher gezeigten Quellcodes an)? \end{enumerate} -\inputcpp{fehler3.cpp} -\inputcpp{fehler4.cpp} +\inputcpp{noBracket\string_broken.cpp} +\inputcpp{wrongDirection\string_broken.cpp} \begin{spiel} \begin{enumerate} @@ -103,7 +106,7 @@ \end{enumerate} \end{spiel} -\inputcpp{fehler5.cpp} +\inputcpp{noSemicolon2\string_broken.cpp} \textbf{Quiz 4}\\ \textit{Was hiervon sind Fehler, die dazu führen, dass eine Datei nicht kompiliert werden kann?}