Skip to content

Commit 1291c24

Browse files
authored
Merge pull request #48 from lucocozz/43-argus-debug
[Refacto] Change `ARGUS_RELEASE` into `ARGUS_DEBUG`
2 parents 68b97a5 + 3cbf5ba commit 1291c24

File tree

6 files changed

+44
-43
lines changed

6 files changed

+44
-43
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- Printing subcommand list on command execution that cannot be executed directly.
1212

13+
### Changed
14+
- Change `ARGUS_RELEASE` into `ARGUS_DEBUG`
15+
1316
### Fixed
1417
- Defining `argus_init()` as a `static inline` function.
1518

docs/docs/getting-started/quickstart.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,13 @@ int main(int argc, char **argv)
6666
6767
```bash
6868
# Development build (recommended during development)
69-
gcc my_tool.c -o my_tool -largus
69+
gcc -DARGUS_DEBUG my_tool.c -o my_tool -largus
7070
./my_tool --help # See auto-generated help
7171
./my_tool input.txt # Run your tool
72-
73-
# Production build (skip validation for better performance)
74-
gcc -DARGUS_RELEASE my_tool.c -o my_tool-prod -largus
7572
```
7673

77-
:::tip Production Note
78-
Use `ARGUS_RELEASE` only in production after thorough testing. It disables option structure validation for faster startup time.
74+
:::tip Development Note
75+
Use `ARGUS_DEBUG` to enable option structure validation and catch configuration errors early.
7976
:::
8077

8178
## // What You Get For Free

includes/argus/api.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,18 @@ ARGUS_API argus_t _argus_init_validate(argus_option_t *options, const char *prog
2727
* @return Initialized argus_t context
2828
*
2929
* @note
30-
* Define `ARGUS_RELEASE` when compiling your application to skip
31-
* options structure validation and improve performance.
30+
* Define `ARGUS_DEBUG` when compiling your application to enable
31+
* options structure validation.
3232
*
33-
* Example: `gcc -DARGUS_RELEASE my_program.c -o my_program -largus`
34-
*
35-
* Note: Only use this in production. During development, leave validation
36-
* enabled to catch configuration errors early.
33+
* Example: `gcc -DARGUS_DEBUG my_program.c -o my_program -largus`
3734
*/
3835
static inline argus_t argus_init(argus_option_t *options, const char *program_name,
3936
const char *version)
4037
{
41-
#ifdef ARGUS_RELEASE
42-
return _argus_init_validate(options, program_name, version, false);
43-
#else
38+
#ifdef ARGUS_DEBUG
4439
return _argus_init_validate(options, program_name, version, true);
40+
#else
41+
return _argus_init_validate(options, program_name, version, false);
4542
#endif
4643
}
4744

includes/argus/options.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ ARGUS_API char *format_choices_validator(validator_data_t data);
6161
/*
6262
* Optional option fields macros
6363
*/
64-
#define DEBUG_INFO() .line = __LINE__, .file = __FILE__
64+
#ifdef ARGUS_DEBUG
65+
# define ARGUS_DEBUG_INFO() .line = 0, .file = NULL
66+
#else
67+
# define ARGUS_DEBUG_INFO() .line = __LINE__, .file = __FILE__
68+
#endif /* ARGUS_DEBUG */
6569
#define DEFINE_NAME(lname, sname) ((lname) ? (lname) : CHAR_TO_STRING(sname))
6670
#define DEFAULT(val) .value = (argus_value_t){ .raw = (uintptr_t)(val) }, \
6771
.default_value = (argus_value_t){ .raw = (uintptr_t)(val) }, \
@@ -134,30 +138,30 @@ ARGUS_API char *format_choices_validator(validator_data_t data);
134138
.type = TYPE_NONE, \
135139
.name = NULL, \
136140
.value_type = VALUE_TYPE_NONE, \
137-
DEBUG_INFO() \
141+
ARGUS_DEBUG_INFO() \
138142
}
139143

140144
#define OPTION_BASE(_short, _long, _value_type, ...) \
141145
(argus_option_t) { \
142146
.type = TYPE_OPTION, .name = DEFINE_NAME(_long, _short), \
143147
.sname = _short, .lname = _long, .value_type = _value_type, \
144-
.free_handler = default_free, DEBUG_INFO(), ##__VA_ARGS__ \
148+
.free_handler = default_free, ARGUS_DEBUG_INFO(), ##__VA_ARGS__ \
145149
}
146150

147151
#define POSITIONAL_BASE(_name, _value_type, ...) \
148152
(argus_option_t) { \
149153
.type = TYPE_POSITIONAL, .name = _name, .value_type = _value_type, \
150-
.free_handler = default_free, .flags = FLAG_REQUIRED, DEBUG_INFO(), ##__VA_ARGS__ \
154+
.free_handler = default_free, .flags = FLAG_REQUIRED, ARGUS_DEBUG_INFO(), ##__VA_ARGS__ \
151155
}
152156

153157
#define GROUP_BASE(_name, ...) \
154158
(argus_option_t) { \
155-
.type = TYPE_GROUP, .name = _name, DEBUG_INFO(), ##__VA_ARGS__ \
159+
.type = TYPE_GROUP, .name = _name, ARGUS_DEBUG_INFO(), ##__VA_ARGS__ \
156160
}
157161

158162
#define SUBCOMMAND_BASE(_name, sub_opts, ...) \
159163
(argus_option_t) { \
160-
.type = TYPE_SUBCOMMAND, .name = _name, .sub_options = sub_opts, DEBUG_INFO(), ##__VA_ARGS__ \
164+
.type = TYPE_SUBCOMMAND, .name = _name, .sub_options = sub_opts, ARGUS_DEBUG_INFO(), ##__VA_ARGS__ \
161165
}
162166

163167
// clang-format on

tests/unit/meson.build

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,36 @@ foreach test : unit_tests
2626
)
2727
endforeach
2828

29-
release_mode_test_sources = files('test_core/test_release_mode.c')
29+
debug_mode_test_sources = files('test_core/test_debug_mode.c')
3030

31-
# Build and run the test in normal mode (validation enabled)
32-
test_release_mode_do_validation = executable(
33-
'test_release_mode_do_validation',
34-
release_mode_test_sources,
31+
# Build and run the test in debug mode (validation enabled)
32+
test_debug_mode_do_validation = executable(
33+
'test_debug_mode_do_validation',
34+
debug_mode_test_sources,
3535
dependencies: [criterion_dep, argus_dep],
3636
include_directories: test_includes,
3737
c_args: test_args
3838
)
3939

4040
test(
41-
'unit_release_mode_do_validation',
42-
test_release_mode_do_validation,
41+
'unit_debug_mode_do_validation',
42+
test_debug_mode_do_validation,
4343
env: test_env,
4444
timeout: 30
4545
)
4646

47-
# Build and run the test in release mode (validation disabled)
48-
test_release_skip_validation = executable(
49-
'test_release_mode_skip_validation',
50-
release_mode_test_sources,
47+
# Build and run the test in standard mode (validation disabled)
48+
test_debug_skip_validation = executable(
49+
'test_debug_mode_skip_validation',
50+
debug_mode_test_sources,
5151
dependencies: [criterion_dep, argus_dep],
5252
include_directories: test_includes,
53-
c_args: test_args + ['-DARGUS_RELEASE'],
53+
c_args: test_args + ['-DARGUS_DEBUG'],
5454
)
5555

5656
test(
57-
'unit_release_mode_skip_validation',
58-
test_release_skip_validation,
57+
'unit_debug_mode_skip_validation',
58+
test_debug_skip_validation,
5959
env: test_env,
6060
timeout: 30
6161
)
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ ARGUS_OPTIONS(
1616
POSITIONAL_STRING("input"),
1717
)
1818

19-
#ifndef ARGUS_RELEASE
19+
#ifdef ARGUS_DEBUG
2020

21-
Test(release_mode, perform_validation, .exit_code = 1, .init = cr_redirect_stderr)
21+
Test(debug_mode, perform_validation, .exit_code = 1, .init = cr_redirect_stderr)
2222
{
2323
argus_t argus = argus_init(invalid_options, "test_program", "1.0.0");
2424

25-
// In release mode, the library should not validate options
25+
// In debug mode, the library should validate options
2626
cr_assert_gt(argus.error_code, 0,
27-
"Errors should be reported in release mode");
27+
"Errors should be reported in debug mode");
2828

2929
argus_free(&argus);
3030
}
3131

3232
#else
3333

34-
Test(release_mode, skip_validation)
34+
Test(debug_mode, skip_validation)
3535
{
3636
argus_t argus = argus_init(invalid_options, "test_program", "1.0.0");
3737

38-
// In debug mode, the library should validate options
39-
cr_assert_eq(argus.error_code, 0,
40-
"Errors should be reported in debug mode");
38+
// In standard mode, the library should not validate options
39+
cr_assert_eq(argus.error_code, 0,
40+
"Errors should not be reported in standard mode");
4141

4242
argus_free(&argus);
4343
}

0 commit comments

Comments
 (0)