-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test for checking the version number matches
- Loading branch information
1 parent
b7ebec6
commit 6a11224
Showing
6 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* SPDX-FileCopyrightText: © 2023 Decompollaborate */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
/** | ||
* Checks every the version numbers of every built package to be the same | ||
*/ | ||
|
||
#include "rabbitizer.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
|
||
const char *const tomlPaths[] = { | ||
"pyproject.toml", | ||
"Cargo.toml", | ||
}; | ||
|
||
|
||
long getFileSize(FILE *file) { | ||
long current = ftell(file); | ||
long totalSize; | ||
|
||
fseek(file, 0L, SEEK_END); | ||
totalSize = ftell(file); | ||
|
||
fseek(file, current, SEEK_SET); | ||
|
||
return totalSize; | ||
} | ||
|
||
#define VERSION_STR_TOML "version = \"" | ||
|
||
int doVersionCheck(const char *filepath, char *buffer) { | ||
char *versionStrPtr = strstr(buffer, VERSION_STR_TOML); | ||
char *endVersionStrPtr; | ||
|
||
if (versionStrPtr == NULL) { | ||
fprintf(stderr, "Could not find version string in file '%s'\n", filepath); | ||
return 1; | ||
} | ||
|
||
// skip initial version stuff | ||
versionStrPtr += strlen(VERSION_STR_TOML); | ||
|
||
endVersionStrPtr = strstr(versionStrPtr, "\""); | ||
if (endVersionStrPtr == NULL) { | ||
fprintf(stderr, "Badly formatted version string in file '%s'\n", filepath); | ||
return 1; | ||
} | ||
|
||
*endVersionStrPtr = '\0'; | ||
|
||
printf("file: '%s', version: '%s'\n", filepath, versionStrPtr); | ||
|
||
if (strcmp(RabVersion_Str, versionStrPtr) != 0) { | ||
fprintf(stderr, "Version of file '%s' does not match\n", filepath); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main() { | ||
size_t i; | ||
int errorCount = 0; | ||
|
||
printf("C package version: '%s'\n", RabVersion_Str); | ||
|
||
for (i = 0; i < ARRAY_COUNT(tomlPaths); i++) { | ||
const char *path = tomlPaths[i]; | ||
FILE *file; | ||
long fileSize; | ||
char *buffer; | ||
|
||
assert(path != NULL); | ||
|
||
file = fopen(path, "r"); | ||
if (file == NULL) { | ||
fprintf(stderr, "Not able to open '%s'\n", path); | ||
errorCount++; | ||
continue; | ||
} | ||
|
||
fileSize = getFileSize(file); | ||
buffer = malloc(fileSize * sizeof(char)); | ||
if (buffer == NULL) { | ||
fclose(file); | ||
fprintf(stderr, "Failed to malloc '%zu' bytes\n", fileSize * sizeof(char)); | ||
errorCount++; | ||
continue; | ||
} | ||
|
||
fread(buffer, sizeof(char), fileSize, file); | ||
|
||
errorCount += doVersionCheck(path, buffer); | ||
|
||
free(buffer); | ||
fclose(file); | ||
} | ||
|
||
return errorCount; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# SPDX-FileCopyrightText: © 2023 Decompollaborate | ||
# SPDX-License-Identifier: MIT | ||
|
||
set -e | ||
|
||
./build/tests/c/build_info_checks/version_number.elf |