CPSC 480-010 Software Engineering (SE) Spring 2023
Project 3: TDD
In Project 3: TDD, you will follow a TDD process to implement code submitted via a GitHub Classroom repository. An invitation link to create the repository is on the Brightspace course page.
Due Dates:
- By
Friday, Mar 10, Monday, Mar 13 11:59:59 pm, create your repository (via GitHub classroom) and make one pass through the TDD workflow (red, green, refactor). Students who miss this deadline will have their overall score for Project 3 reduced by 10 points (one letter grade). I strongly advise that you start right away.
- The rest of the project is due by 11:59:59 pm on
Friday, Mar 17 Monday, Mar 27.
The input for a (source) code-analysis project is source code that can come from multiple sources, including solitary files (e.g., main.cpp), directories of source-code files (e.g., src/), source-code archives (e.g., project.tar.gz, file.zip), and standard input (i.e., stdin, e.g., std::cin).
In addition, solitary files and source-code archives can include a URL, e.g., https://raw.githubusercontent.com/UAComputerScience/sorttdd-mlcollard/main/sortTest.cpp
To perform the code analysis, the source code is wrapped in a single XML element with metadata about the source code, including filename, programming language, url, hash, and LOC (lines of code). For the source-code example, the resulting XML has the following attributes:
Attribute |
XML Example |
language |
language="C++" |
url |
url="http://mlcollard.net/fragment.cpp" |
filename |
filename="fragment.cpp" |
LOC |
loc="3" |
hash |
hash="39dcad4f59855aa76420aa3d69af3d7ba30a91bb" |
The hash is of the source and is a SHA1 160-bit (20 bytes) represented in 40 hex characters, which Git uses. Note that the xmlns:code="http://mlcollard.net/code"
is not an attribute, but an XML namespace declaration, handled automatically by XMLWrapper.
The programming language is typically determined from the file extension, e.g., .cpp for C++, but exceptions exist. The variety of input sources and program options for the metadata follows the rules stated below.
Assignment
Implement the below rules following a Test-Driven Development (TDD) approach. Write a test in CodeAnalysisTest.cpp, and implement the minimal code necessary to get it working in CodeAnalysis.cpp, refactor/clean up the code to make it clear and logical, then commit with an appropriate commit message. You are encouraged to commit more than once per test case, e.g., after entering the minimal code to solve the problem and refactor/clean up the code.
- The code you have to implement is in the function formatAnalysisXML()
- You cannot create or use new functions besides the given code.
- A CMake build is provided.
- Do not change or create tests for the function filenameToLanguage(), as they are already completed and tested.
Rules
- If you cannot figure out the attribute language based on any other rule, use the default language.
- For a regular file on disk, in most cases, the file extension of the disk filename determines the language, e.g., for main.cpp, the language is C++. Use the provided function, filenameToLanguage(), to convert from a filename to a language for a regular file's attribute language.
- For a file in a source-code archive, in most cases, the file extension of the entry filename determines the language, e.g., for the entry filename main.cpp, the language is C++. Use the provided function, filenameToLanguage(), to convert from a filename to a language for the attribute language for a file in a source-code archive.
- The option language has priority over any other way of determining the attribute language.
- When the source url is not empty, use it for the attribute url.
- When used, the option url has priority over the source url for the attribute url.
- When the option hash is not empty, use it for the attribute hash.
- The option filename has priority over any other way of determining the attribute filename.
- For a source-code archive, use the entry filename instead of the disk filename for the attribute filename.
- For a regular file use the disk filename for the attribute filename.
- For standard input (i.e.,
std::cin
) of a regular file, the disk filename is a single dash "-" and the entry filename is the literal string "data". In this case, you must use the option filename for the attribute filename.
- For standard input (i.e.,
std::cin
) of a source-code archive, the disk filename is a single dash "-". In this case, use the entry filename for the attribute filename.
- The minimum LOC is 0. If the option loc is non-negative, add the attribute loc.
Error Handling
All error messages are written to standard error (i.e., std::cerr), and the function should return an empty string.
- If the file extension is used to determine the language, and there is no mapping for that language, output the error message “Extension not supported”
- When the input is from standard input, and a language cannot be determined, output the error message “Using stdin requires a declared language”
Grading
Your score will depend on the following:
- Following the TDD process. This must be reflected in your commit history, both when commits are made and the commit messages.
- Successful implementation of the rules
- Following the commit message guidelines.
- Coding style, including use of if-statements. The function logic should be as simple as possible. Pay attention to the coding style criteria given in class.