mirror of
https://github.com/Wessel/boilerplate-c.git
synced 2026-07-15 12:33:36 +02:00
feat: Modernize boilerplate
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
cpp_indent_braces=false
|
||||
cpp_indent_multi_line_relative_to=innermost_parenthesis
|
||||
cpp_indent_within_parentheses=indent
|
||||
@@ -57,8 +64,3 @@ cpp_space_around_assignment_operator=insert
|
||||
cpp_space_pointer_reference_alignment=left
|
||||
cpp_space_around_ternary_operator=insert
|
||||
cpp_wrap_preserve_blocks=one_liners
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
@@ -1,2 +0,0 @@
|
||||
node_modules/
|
||||
dist/
|
||||
66
.eslintrc
66
.eslintrc
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"amd": true,
|
||||
"jest": true,
|
||||
"node": true,
|
||||
"mongo": true,
|
||||
"jquery": true,
|
||||
"browser": true,
|
||||
"commonjs": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"ecmaFeatures": {
|
||||
"jsx": true,
|
||||
"forOf": true,
|
||||
"spread": true,
|
||||
"modules": true,
|
||||
"classes": true,
|
||||
"generators": true,
|
||||
"restParams": true,
|
||||
"regexUFlag": true,
|
||||
"regexYFlag": true,
|
||||
"globalReturn": true,
|
||||
"destructuring": true,
|
||||
"impliedStrict": true,
|
||||
"blockBindings": true,
|
||||
"defaultParams": true,
|
||||
"octalLiterals": true,
|
||||
"arrowFunctions": true,
|
||||
"binaryLiterals": true,
|
||||
"templateStrings": true,
|
||||
"superInFunctions": true,
|
||||
"unicodeCodePointEscapes": true,
|
||||
"experimentalObjectRestSpread": true,
|
||||
"objectLiteralShorthandMethods": true,
|
||||
"objectLiteralComputedProperties": true,
|
||||
"objectLiteralDuplicateProperties": true,
|
||||
"objectLiteralShorthandProperties": true
|
||||
}
|
||||
},
|
||||
"plugins": [],
|
||||
"rules": {
|
||||
"semi": "warn",
|
||||
"indent": [ "off", "error" ],
|
||||
"strict": "off",
|
||||
"eqeqeq": "error",
|
||||
"no-var": "warn",
|
||||
"no-undef": "warn",
|
||||
"valid-jsdoc": "warn",
|
||||
"comma-dangle": "warn",
|
||||
"no-dupe-args": "warn",
|
||||
"no-dupe-keys": "warn",
|
||||
"require-await": "warn",
|
||||
"spaced-comment": "error",
|
||||
"space-in-parens": "error",
|
||||
"no-global-assign": "warn",
|
||||
"no-duplicate-imports": "error",
|
||||
"no-dupe-class-members": "error"
|
||||
},
|
||||
"globals": {
|
||||
"_config": false,
|
||||
"console": false
|
||||
}
|
||||
}
|
||||
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@@ -1 +1 @@
|
||||
* @Wessel
|
||||
* @{{project.master}}
|
||||
|
||||
27
.github/CONTRIBUTING.md
vendored
27
.github/CONTRIBUTING.md
vendored
@@ -1,38 +1,13 @@
|
||||
# Contributing
|
||||
|
||||
<!---
|
||||
Used linters:
|
||||
[ESLint](https://eslint.org/)
|
||||
[EditorConfig](https://editorconfig.org)
|
||||
--->
|
||||
|
||||
If you wish to contribute to {{project.name}}, feel free to fork the repository and submit a pull request.
|
||||
{{project.linter}} is enforced to correct most typo's you make and keep the code style the same throughout the whole project,
|
||||
so it would be much appreciated if you installed {{project.linter}} to your editor of choice
|
||||
|
||||
<!---
|
||||
Prerequisites for Node.JS:
|
||||
|
||||
* [Node.JS V18.14.0](https://nodejs.org/en/)
|
||||
* [Docker](https://www.docker.com)
|
||||
* [ESLint](https://eslint.org)
|
||||
* [(OPTIONAL) Yarn](https://yarnpkg.com)
|
||||
--->
|
||||
## Prerequisites
|
||||
The following prerequisites must be met before installing {{project.name}}:
|
||||
{{setup.prerequisites}}
|
||||
|
||||
<!---
|
||||
Install commands:
|
||||
JavaScript/TypeScript: `yarn --dev` or `npm install --dev`
|
||||
Rust: `cargo run`
|
||||
C: `make clean install`
|
||||
|
||||
Run commands:
|
||||
JavaScript/TypeScript: `yarn test` or `npm run test`
|
||||
Rust: `cargo run`
|
||||
C: `make clean dev`
|
||||
--->
|
||||
## Setup
|
||||
To get ready to work on the codebase, please do the following:
|
||||
|
||||
@@ -46,4 +21,4 @@ When creating any new functions, please also create unit tests for them in the `
|
||||
Use the library associated with the project when creating such tests.
|
||||
|
||||
When modifying existing functions, make sure to test them before making a pull request, this will prevent
|
||||
anything from breaking on the production environment.
|
||||
anything from breaking on the production environment.
|
||||
|
||||
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@@ -1,2 +1 @@
|
||||
github: wessel
|
||||
ko_fi: wessel
|
||||
{{project.funding}}
|
||||
|
||||
12
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
12
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -1,18 +1,12 @@
|
||||
# Adapted from https://github.com/discordjs/discord.js/blob/main/.github/ISSUE_TEMPLATE/bug_report.yml
|
||||
name: Bug report
|
||||
description: Report incorrect or unexpected behavior of a package
|
||||
labels: [bug, need repro]
|
||||
body:
|
||||
# - type: markdown
|
||||
# attributes:
|
||||
# value: |
|
||||
# Use Discord for questions: https://discord.gg/djs
|
||||
- type: dropdown
|
||||
id: package
|
||||
attributes:
|
||||
label: Which part is this bug report for?
|
||||
options:
|
||||
- {{tree.parts}}
|
||||
options: {{tree.parts}}
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -48,7 +42,7 @@ body:
|
||||
- type: input
|
||||
id: lang-version
|
||||
attributes:
|
||||
label: {{project.lang}} version
|
||||
label: '{{project.lang}} version'
|
||||
description: |
|
||||
Which version of {{project.lang}} are you using?
|
||||
validations:
|
||||
@@ -75,4 +69,4 @@ body:
|
||||
label: I have tested this issue on a development release
|
||||
placeholder: d23280c (commit hash)
|
||||
description: |
|
||||
The issue might already be fixed in a development release or main. This is not required, but helps us greatly.
|
||||
The issue might already be fixed in a development release or main. This is not required, but helps us greatly.
|
||||
|
||||
7
.github/ISSUE_TEMPLATE/config.yml
vendored
7
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,7 +1,2 @@
|
||||
blank_issues_enabled: false
|
||||
# Example entry:
|
||||
# name:
|
||||
# url:
|
||||
# about:
|
||||
contact_links:
|
||||
- {{project.contact}}
|
||||
{{project.contact}}
|
||||
|
||||
6
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
6
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@@ -1,4 +1,3 @@
|
||||
# Adapted from https://github.com/discordjs/discord.js/blob/main/.github/ISSUE_TEMPLATE/feature_request.yml
|
||||
name: Feature request
|
||||
description: Request a new feature
|
||||
labels: [feature request]
|
||||
@@ -11,8 +10,7 @@ body:
|
||||
id: package
|
||||
attributes:
|
||||
label: Which part is this feature request for?
|
||||
options:
|
||||
- {{tree.parts}}
|
||||
options: {{tree.parts}}
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
@@ -39,4 +37,4 @@ body:
|
||||
id: additional-context
|
||||
attributes:
|
||||
label: Other context
|
||||
description: Any other context, screenshots, or file uploads that help us understand your feature request.
|
||||
description: Any other context, screenshots, or file uploads that help us understand your feature request.
|
||||
|
||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -3,8 +3,6 @@ name: Pull Request
|
||||
about: Propose changes to {{project.name}}
|
||||
title: "[PR] Your changes"
|
||||
labels: pullrequest
|
||||
assignees: Wessel
|
||||
|
||||
---
|
||||
|
||||
**Please describe the changes this PR makes and why it should be merged:**
|
||||
|
||||
5
.github/auto_assign.yml
vendored
5
.github/auto_assign.yml
vendored
@@ -1,5 +1,4 @@
|
||||
addReviewers: true
|
||||
reviewers:
|
||||
- {{project.reviewers}}
|
||||
reviewers: {{project.reviewers}}
|
||||
numberOfReviewers: 0
|
||||
runOnDraft: true
|
||||
runOnDraft: true
|
||||
|
||||
13
.gitignore
vendored
13
.gitignore
vendored
@@ -1,9 +1,6 @@
|
||||
# C build files
|
||||
**/*.o
|
||||
**/out/*
|
||||
|
||||
**/tmp/*
|
||||
!.gitkeep
|
||||
|
||||
tmp/
|
||||
src/tmp
|
||||
|
||||
node_modules/
|
||||
|
||||
obj/
|
||||
out/
|
||||
2
LICENSE
2
LICENSE
@@ -1,7 +1,7 @@
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2023 Wessel T <discord@go2it.eu> (https://wessel.gg/)
|
||||
Copyright (c) {{project.license}}
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
30
README.md
30
README.md
@@ -1,40 +1,12 @@
|
||||
<!---
|
||||
To update:
|
||||
project.
|
||||
master - The master org or user of the repo
|
||||
linter - The linter used for the project
|
||||
name - Project name
|
||||
lang - The (primary) programming language used
|
||||
logo - Project logo
|
||||
contact - All ways to contact for any inqueries
|
||||
reviewers - A list of users to auto-assign to issues and features
|
||||
info.
|
||||
toc - Table of Contents of README
|
||||
desc - Small project description
|
||||
badges - Any extra badges
|
||||
setup.
|
||||
prerequisites - The prerequisites needed to run the project
|
||||
install - Command for initial installation
|
||||
test - Command for running tests
|
||||
tree.
|
||||
parts - All individual parts of the project
|
||||
--->
|
||||
<img src="{{project.logo}}" align="left" width="192px" height="192px"/>
|
||||
<img align="left" width="0" height="192px" hspace="10"/>
|
||||
|
||||
> {{project.name}}
|
||||
|
||||
[](/LICENSE) {{info.badges}}
|
||||
[](/LICENSE)
|
||||
|
||||
{{info.desc}}
|
||||
|
||||
<br><br>
|
||||
|
||||
<!---
|
||||
Example table of contents:
|
||||
* header
|
||||
* sub header
|
||||
--->
|
||||
## Table of contents
|
||||
{{info.toc}}
|
||||
|
||||
|
||||
86
init_repo.py
Normal file
86
init_repo.py
Normal file
@@ -0,0 +1,86 @@
|
||||
import os
|
||||
import yaml
|
||||
import re
|
||||
import datetime
|
||||
|
||||
file_types = ['LICENSE', 'CODEOWNERS', '.md', '.yml']
|
||||
script_name = os.path.basename(__file__)
|
||||
|
||||
def replace_placeholders(file_path, replacements):
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
|
||||
for placeholder, replacement in replacements.items():
|
||||
content = re.sub(re.escape(placeholder), replacement, content)
|
||||
|
||||
with open(file_path, 'w', encoding='utf-8') as file:
|
||||
file.write(content)
|
||||
|
||||
def initialize_repository(directory, replacements):
|
||||
for root, _, files in os.walk(directory):
|
||||
for file in files:
|
||||
if file == script_name:
|
||||
continue
|
||||
if any(file.endswith(file_type) for file_type in file_types):
|
||||
file_path = os.path.join(root, file)
|
||||
replace_placeholders(file_path, replacements)
|
||||
|
||||
def parse_input(prompt):
|
||||
return [item.strip() for item in input(prompt).split(',')]
|
||||
|
||||
def parse_contact(prompt):
|
||||
contacts = []
|
||||
while True:
|
||||
print(prompt)
|
||||
name = input(f"\tName\t\t").strip()
|
||||
if not name:
|
||||
break
|
||||
url = input(f"\tURL\t\t").strip()
|
||||
about = input(f"\tAbout\t\t").strip()
|
||||
contacts.append({'name': name, 'url': url, 'about': about})
|
||||
return {'contact_links': contacts}
|
||||
|
||||
def parse_funding(prompt):
|
||||
funding = {}
|
||||
while True:
|
||||
print(prompt)
|
||||
key = input(f"\tKey\t\t").strip()
|
||||
if not key:
|
||||
break
|
||||
value = input(f"\tValue\t\t").strip()
|
||||
funding[key] = value
|
||||
|
||||
return funding
|
||||
|
||||
def main():
|
||||
current_year = str(datetime.datetime.now().year)
|
||||
|
||||
replacements = {
|
||||
"{{project.name}}": input("Project name\t\t"),
|
||||
"{{info.desc}}": input("Project Description\t"),
|
||||
"{{project.master}}": input("Master of the repo\t"),
|
||||
"{{project.license}}": f"{current_year} " + input('License holder\t\t'),
|
||||
|
||||
"{{tree.parts}}": yaml.dump(parse_input("Parts of the repo\t"), default_flow_style=True),
|
||||
"{{project.lang}}": input("Language used\t\t"),
|
||||
"{{project.linter}}": input("Linter used\t\t"),
|
||||
|
||||
"{{setup.prerequisites}}": input("Prerequisites\t\t"),
|
||||
"{{setup.install}}": input("Install command\t\t"),
|
||||
"{{setup.test}}": input("Test command\t\t"),
|
||||
|
||||
"{{project.logo}}": input("Project logo URL\t"),
|
||||
"{{project.funding}}": yaml.dump(parse_funding("Funding methods\t\t"), default_flow_style=True),
|
||||
"{{project.contact}}": yaml.dump(parse_contact("Contact information\t"), default_flow_style=False),
|
||||
"{{project.reviewers}}": yaml.dump(parse_input("Auto-assign users (x,y)\t"), default_flow_style=True)
|
||||
}
|
||||
|
||||
directory = input("Initialize directory\t") or '.'
|
||||
initialize_repository(directory, replacements)
|
||||
|
||||
delete = input("Delete this script? (Y/n)\t") or "y"
|
||||
if delete.lower() == "y":
|
||||
os.remove(__file__)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -12,7 +12,7 @@ This file is licensed under the LGPL
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include "tap.h"
|
||||
#include "libtap.h"
|
||||
|
||||
static int expected_tests = NO_PLAN;
|
||||
static int failed_tests;
|
||||
|
||||
24
lib/macros.h
Normal file
24
lib/macros.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/* macros.h */
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef MACROS_H
|
||||
#define MACROS_H
|
||||
|
||||
enum DEBUG_STATE { INACTIVE, ACTIVE };
|
||||
|
||||
#ifndef __DEBUG__
|
||||
#define __DEBUG__ ACTIVE
|
||||
#endif
|
||||
|
||||
/** @brief Prints to the console only if DEBUG = 1 **/
|
||||
#define dbg(fmt, ...) do { \
|
||||
if (__DEBUG__ == ACTIVE) \
|
||||
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define dbg_no_info(fmt, ...) do { \
|
||||
if (__DEBUG__ == ACTIVE) \
|
||||
fprintf(stderr, fmt, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
/* util.h */
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
33
makefile
33
makefile
@@ -7,15 +7,21 @@ LIB_DIR := lib
|
||||
OBJ_DIR := obj
|
||||
OUT_DIR := out
|
||||
INC_DIR := include
|
||||
TST_DIR := test
|
||||
|
||||
# Map all object and source files
|
||||
SRC_FILES := $(wildcard $(SRC_DIR)/*.c) $(wildcard $(LIB_DIR)/*.c)
|
||||
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC_FILES))
|
||||
SRC_FILES := $(wildcard $(SRC_DIR)/**/*.c) $(wildcard $(LIB_DIR)/**/*.c)
|
||||
OBJ_FILES := $(patsubst $(SRC_DIR)/**/%.c,$(OBJ_DIR)/%.o,$(SRC_FILES))
|
||||
|
||||
TST_FILES := $(wildcard $(TST_DIR)/*.c) $(wildcard $(LIB_DIR)/*.c)
|
||||
OBJ_TST_FILES := $(patsubst $(TST_DIR)/%.c,$(OBJ_DIR)/%.o,$(TST_FILES))
|
||||
|
||||
# All optional libs and Cflags to append to the final command
|
||||
LIBS := -lm
|
||||
LIBS :=
|
||||
CFLAGS := -I$(INC_DIR)
|
||||
BUILDFLAGS := -Wall -Wextra -Wconversion
|
||||
DEBUGFLAGS :=
|
||||
BUILDFLAGS :=
|
||||
WARNFLAGS := -Wall -Wextra -Wconversion
|
||||
|
||||
# Special and default commands
|
||||
.PHONY: clean help
|
||||
@@ -25,6 +31,9 @@ BUILDFLAGS := -Wall -Wextra -Wconversion
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
$(CC) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/%.o: $(TST_DIR)/%.c
|
||||
$(CC) -c -o $@ $<
|
||||
|
||||
## All make commands ##
|
||||
help: ## Lists all commands
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||
@@ -33,10 +42,20 @@ clean: ## Clean up all object files and executables
|
||||
rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/*
|
||||
|
||||
dev: $(OBJ_FILES) ## Build, run and debug the project
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && strace ./out/dev
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) $(DEBUGFLAGS) && ./out/dev
|
||||
|
||||
run: $(OBJ_FILES) ## Build and run the project
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && ./out/run
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) $(WARNFLAGS) && ./out/run
|
||||
|
||||
prod: $(OBJ_FILES) ## Build the project
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(BUILDFLAGS) $(LIBS)
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) $(BUILDFLAGS) $(WARNFLAGS)
|
||||
|
||||
test: $(OBJ_TST_FILES) ## Build tests and run them
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && ./out/test \
|
||||
--port 6060 --timeout 500
|
||||
|
||||
valgrind: $(OBJ_FILES) ## Build the project and run with Valgrind
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && valgrind ./out/valgrind
|
||||
|
||||
strace: $(OBJ_FILES) ## Build the project and run with strace
|
||||
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && strace ./out/strace
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Contains object files generated by make
|
||||
@@ -0,0 +1 @@
|
||||
Contains executables generated by make
|
||||
@@ -6,9 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../include/utils.h"
|
||||
/* Libtap for tests */
|
||||
#include "../include/libtap.h"
|
||||
#include "../../lib/util.h"
|
||||
|
||||
int main(int argc, char *argv[], char *env[]) {
|
||||
return 0;
|
||||
|
||||
58
test/argp.test.c
Normal file
58
test/argp.test.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* argp.test.c */
|
||||
#include <argp.h>
|
||||
|
||||
#include "../lib/libtap.h"
|
||||
#include "../lib/macros.h"
|
||||
|
||||
// Define the structure to store the arguments
|
||||
struct arguments {
|
||||
int port;
|
||||
int timeout;
|
||||
};
|
||||
|
||||
// Define the argument parser
|
||||
static struct argp_option options[] = {
|
||||
{"port", 'p', "PORT", 0, "Port number"},
|
||||
{"timeout", 't', "TIMEOUT", 0, "Timeout in seconds"},
|
||||
{0}
|
||||
};
|
||||
|
||||
static error_t parse_opt(int key, char* arg, struct argp_state* state) {
|
||||
struct arguments* arguments = state->input;
|
||||
switch (key) {
|
||||
case 'p':
|
||||
arguments->port = atoi(arg);
|
||||
break;
|
||||
case 't':
|
||||
arguments->timeout = atoi(arg);
|
||||
break;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct argp argp = { options, parse_opt, 0, 0 };
|
||||
|
||||
|
||||
|
||||
void run_argp_tests(int argc, char* argv[], char* env[]) {
|
||||
|
||||
printf("\033[0;35m--Tests for parsing CL args--\033[0;0m\n");
|
||||
|
||||
/* Unit tests for parsing console arguments */
|
||||
struct arguments args;
|
||||
|
||||
// Set default values for the arguments
|
||||
args.port = 8080;
|
||||
args.timeout = 10;
|
||||
dbg("defaults(Arguments { port: 8080, timeout: 10 })\n", NULL);
|
||||
|
||||
// Parse the arguments
|
||||
argp_parse(&argp, argc, argv, 0, 0, &args);
|
||||
dbg("parsed(Arguments { port: %d, timeout: %d })\n", args.port, args.timeout);
|
||||
|
||||
ok(args.port == 6060, "Arg `port` is `6060`");
|
||||
ok(args.timeout == 500, "Arg `timeout` is `500`");
|
||||
|
||||
}
|
||||
42
test/main.test.c
Normal file
42
test/main.test.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* main.test.c */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "main.test.h"
|
||||
#include "../lib/libtap.h"
|
||||
#include "../lib/macros.h"
|
||||
|
||||
int main(int argc, char* argv[], char* env[]) {
|
||||
srand(time(NULL));
|
||||
|
||||
/* Debug log: argv variables */
|
||||
dbg("argc:\t%d\n", argc);
|
||||
dbg("argv:\t", NULL);
|
||||
for (int i = 0; i < argc; i++) dbg_no_info("%s ", argv[i]);
|
||||
dbg_no_info("\n", NULL);
|
||||
|
||||
/* Debug log: env variables */
|
||||
dbg("env:\t", NULL);
|
||||
|
||||
int colors[] = { 31, 32, 33, 34, 35 };
|
||||
int colors_len = 4;
|
||||
int colors_i = 0;
|
||||
|
||||
for (int i = 0; env[i] != NULL; i++) {
|
||||
dbg_no_info("\033[0;%dm%s\033[0;0m ", colors[colors_i], env[i]);
|
||||
colors_i = colors_i == colors_len ? 0 : colors_i + 1;
|
||||
}
|
||||
|
||||
dbg_no_info("\n", NULL);
|
||||
|
||||
/* Initialize unit tests */
|
||||
plan(2);
|
||||
|
||||
dbg("Running `run_argp_tests`\n", NULL);
|
||||
run_argp_tests(argc, argv, env);
|
||||
|
||||
done_testing();
|
||||
|
||||
return 0;
|
||||
}
|
||||
7
test/main.test.h
Normal file
7
test/main.test.h
Normal file
@@ -0,0 +1,7 @@
|
||||
/* main.test.h */
|
||||
#ifndef TESTS_H
|
||||
#define TESTS_H
|
||||
|
||||
void run_argp_tests(int argc, char* argv[], char* env[]);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user