ThrowTheSwitch / Ceedling

Ruby-based unit testing and build system for C projects

Home Page:http://throwtheswitch.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The "clean" doesn't help if file name capitalization has changed

GlebPlekhotko opened this issue · comments

Hello everyone!

An issue for the record.

Let's consider we create the "test_unit.c" file containing some tests in it. It looks as follows:

#include <unity.h>

void setUp(void)
{
    ;
}

void tearDown(void)
{
    ;
}

void test_success(void)
{
    TEST_PASS();
}

Next we run it and obtain the following output:

F:\sandbox>ceedling test:all

Test 'test_unit.c'
------------------
Generating runner for test_unit.c...
Compiling test_unit_runner.c...
Compiling test_unit.c...
Compiling unity.c...
Compiling cmock.c...
Linking test_unit.out...
Running test_unit.out...

--------------------
OVERALL TEST SUMMARY
--------------------
TESTED:  1
PASSED:  1
FAILED:  0
IGNORED: 0

Perfectly fine. Then, for some reason, we decide to rename the "test_unit.c" to the "test_Unit.c". To run it again, we first execute the "ceedling clean" command to clean the leftovers if any, then run "ceedling test:all" again. And it fails:

F:\sandbox>ceedling clean

Cleaning build artifacts...
(For large projects, this task may take a long time to complete)

F:\sandbox>ceedling test:all

Test 'test_Unit.c'
------------------
ERROR: Found no file 'test_Unit_runner.c' in search paths. However, a filename having different capitalization was found: 'build/test/runners/test_unit_runner.c'.
#<Thread:0x0000021dadda47e8 C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/par_map.rb:7 run> terminated with exception (report_on_exception is true):
C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/file_finder_helper.rb:45:in `blow_up': unhandled exception
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/file_finder_helper.rb:22:in `block in find_file_in_collection'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/file_finder_helper.rb:12:in `each'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/file_finder_helper.rb:12:in `find_file_in_collection'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/file_finder.rb:102:in `block in find_compilation_input_file'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/file_finder.rb:98:in `synchronize'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/file_finder.rb:98:in `find_compilation_input_file'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/rules_tests.rake:13:in `block in <top (required)>'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:307:in `block in make_sources'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:294:in `map'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:294:in `make_sources'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:272:in `attempt_rule'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:156:in `block in enhance_with_matching_rule'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:154:in `each'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:154:in `enhance_with_matching_rule'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task_manager.rb:57:in `[]'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task.rb:405:in `[]'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/rake_wrapper.rb:18:in `[]'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/task_invoker.rb:97:in `block in invoke_test_objects'
        from C:/WorkSoft/PC/Ruby/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/lib/ceedling/par_map.rb:10:in `block (2 levels) in par_map'
rake aborted!


Tasks: TOP => test:all
(See full trace by running task with --trace)

--------------------
OVERALL TEST SUMMARY
--------------------

No tests executed.

To make it work, we must either completely clean the "build" directory or remove the respective runner from the "build\runners" directory. In the particular case, it is the "test_unit_runner.c":

F:\sandbox>ceedling test:all

Test 'test_Unit.c'
------------------
Generating runner for test_Unit.c...
Compiling test_Unit_runner.c...
Compiling test_Unit.c...
Compiling unity.c...
Compiling cmock.c...
Linking test_Unit.out...
Running test_Unit.out...

--------------------
OVERALL TEST SUMMARY
--------------------
TESTED:  1
PASSED:  1
FAILED:  0
IGNORED: 0

Environment:

  • Windows 10;
  • MinGW;
  • ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x64-mingw32];
  • project configuration is default one generated by the "ceedling new";
  • Ceedling:: 0.31.1;
  • Unity:: 2.5.4;
  • CMock:: 2.5.4;
  • CException:: 1.3.3;

Thanks for your time and good luck.

what about ceedling clobber

@GlebPlekhotko Strictly speaking, this is not a Ceedling issue. It's an OS / file system issue. The behavior depends on how your file system handles capitalization in filenames. For instance, on the Unix variant I'm using, if a file already exists with one capitalization but calls write data to the same filename with a different capitalization, the original case of the filename is preserved while the content of the file changes. This is what is biting you. Unfortunately, this is a wildly complicated topic to handle in a platform agnostic way. A @kafkaaaa suggests, clobber is the best option, albeit a brute force option, for handling capitalization changes in filenames.