List of commits:
Subject Hash Author Date (UTC)
assert 6ba991dbb9b5606355f73c71fca85d80bd169bf9 Ubuntu 2020-03-29 04:59:45
cleanup f5cbde963e841bf63f51cc28ec389b6580345ed3 Ubuntu 2020-03-29 04:42:07
deepmerge aee7de1ccef07d1162231fad345a1dc1513452fb Ubuntu 2020-03-29 04:39:34
init e6d74419d4aaaa415732b596065b2f5cd67d66ef Ubuntu 2020-03-28 22:44:10
Commit 6ba991dbb9b5606355f73c71fca85d80bd169bf9 - assert
Author: Ubuntu
Author date (UTC): 2020-03-29 04:59
Committer name: Ubuntu
Committer date (UTC): 2020-03-29 04:59
Parent(s): f5cbde963e841bf63f51cc28ec389b6580345ed3
Signing key:
Tree: 0243f048cedb5e83234df8600549004677600560
File Lines added Lines deleted
asserter/.gitignore 3 0
asserter/README.md 3 0
asserter/def.json 11 0
asserter/package.json 9 0
asserter/src/archiver.cpp 67 0
asserter/src/archiver.h 28 0
asserter/src/asserter.cpp 78 0
asserter/src/asserter.h 88 0
asserter/src/asserter.hxx 8 0
asserter/src/test.h 10 0
asserter/test/lib/asserter 1 0
asserter/test/src/check_assert.cpp 14 0
asserter/test/test.js 56 0
asserter/test/test.json 5 0
index.js 2 1
File asserter/.gitignore added (mode: 100644) (index 0000000..804508d)
1 .DS_Store
2 test/tmp/
3 node_modules/
File asserter/README.md added (mode: 100644) (index 0000000..1ef13e9)
1 # assertertest
2
3 ![doc header](https://s3-us-west-2.amazonaws.com/mod-resources/mod-header.svg)
File asserter/def.json added (mode: 100644) (index 0000000..efa50db)
1 {
2 "sources":
3 [
4 "src/archiver.cpp",
5 "src/archiver.h",
6 "src/asserter.cpp",
7 "src/asserter.h",
8 "src/asserter.hxx",
9 "src/test.h"
10 ]
11 }
File asserter/package.json added (mode: 100644) (index 0000000..ef870de)
1 {
2 "scripts": {
3 "test": "tape test/test.js"
4 },
5 "dependencies": {
6 "expector": "*",
7 "tape": "*"
8 }
9 }
File asserter/src/archiver.cpp added (mode: 100644) (index 0000000..2f6e4e1)
1 #include <cstring>
2 #include <fstream>
3 #include <sstream>
4 #include <vector>
5
6 #include "archiver.h"
7
8 using namespace std;
9
10 namespace private_assert
11 {
12 archiver & archiver::instance()
13 {
14 static archiver local;
15 return local;
16 }
17
18 archiver::~archiver()
19 {
20 fstream out( "result.json", fstream::out );
21
22 out << "{\n";
23 out << "\"passed\": " << m_passed;
24
25 if (m_failed.begin() != m_failed.end())
26 {
27 out << "," << endl;
28
29 auto i( m_failed.begin() );
30 out << "\"failed\": [" << endl << *(i++) << endl;
31 while (i != m_failed.end())
32 out << ", " << *(i++) << endl;
33 out << "]" << endl;
34 }
35 else {
36 out << endl;
37 }
38 out << "}\n";
39 }
40
41 void archiver::pass()
42 {
43 ++m_passed;
44 }
45
46 void archiver::fail(
47 const char * file,
48 int line,
49 const char * function,
50 const char * message )
51 {
52
53 stringstream entry;
54 entry << "{" << endl;
55
56 if (strlen(message))
57 {
58 entry << "\"message\":\"" << message << "\"," << endl;
59 }
60 entry << "\"file\":\"" << file << "\"," << endl;
61 entry << "\"function\":\"" << function << "\"," << endl;
62 entry << "\"line\":" << line << endl;
63 entry << "}" << endl;
64
65 m_failed.push_back( entry.str() );
66 }
67 } // private_assert
File asserter/src/archiver.h added (mode: 100644) (index 0000000..3efe692)
1 #ifndef ARCHIVER_INCLUDE_GUARD_03K9027KSIQ
2 #define ARCHIVER_INCLUDE_GUARD_03K9027KSIQ
3
4 #include <iostream>
5 #include <vector>
6 #include <string>
7
8 namespace private_assert
9 {
10 struct archiver
11 {
12 static archiver & instance();
13
14 ~archiver();
15
16 void pass();
17 void fail(
18 const char *,
19 int,
20 const char * function,
21 const char * = "");
22 private:
23 std::size_t m_passed = 0;
24 std::vector< std::string > m_failed;
25 };
26 }
27
28 #endif // ARCHIVER_INCLUDE_GUARD_03K9027KSIQ
File asserter/src/asserter.cpp added (mode: 100755) (index 0000000..13ac8b7)
1 #include <assert.h>
2
3 #include "archiver.h"
4 #include "asserter.h"
5
6 #undef SMART_ASSERT_A
7 #undef SMART_ASSERT_B
8 #undef SMART_ASSERT_OP
9 #undef SMART_ASSERT
10
11 #ifndef NDEBUG
12
13 /////////////////////////////////////////////////////////////////////////////////////////////
14 // asserter_t
15 /////////////////////////////////////////////////////////////////////////////////////////////
16 asserter_t::asserter_t(bool value)
17 : SMART_ASSERT_A( * this )
18 , SMART_ASSERT_B( * this )
19 , m_value( value )
20 {}
21
22 /////////////////////////////////////////////////////////////////////////////////////////////
23 bool asserter_t::pass() const
24 {
25 return m_value;
26 }
27
28 /////////////////////////////////////////////////////////////////////////////////////////////
29 const asserter_t & asserter_t::print_message(
30 const char * file,
31 int line,
32 const char * function,
33 const char * message) const
34 {
35 static const char * code_red( "\x1b[31m" );
36 static const char * code_reset( "\x1b[39;49m" );
37
38 using namespace std;
39
40 if (pass())
41 {
42 cout << "assertion passed: " << message << endl
43 << "file: " << file << endl
44 << "line: " << line << endl
45 << "function: " << function << endl;
46 }
47 else
48 {
49 cout << code_red
50 << "assertion failed: " << message << endl
51 << "file: " << file << endl
52 << "line: " << line << endl
53 << "function: " << function
54 << code_reset << endl;
55 }
56 return * this;
57 }
58
59 /////////////////////////////////////////////////////////////////////////////////////////////
60 const asserter_t & asserter_t::archive_result(
61 const char * file,
62 int line,
63 const char * function,
64 const char * message ) const
65 {
66 auto & a( private_assert::archiver::instance() );
67 if (pass())
68 a.pass();
69 else
70 a.fail( file, line, function, message );
71 return * this;
72 }
73
74 #endif // NDEBUG
75
76
77
78
File asserter/src/asserter.h added (mode: 100755) (index 0000000..de41d80)
1 /*
2 Reference: http://www.drdobbs.com/article/print?articleId=184403745
3 */
4
5 #ifndef ASSERT_H_9879879hkjh
6 #define ASSERT_H_9879879hkjh
7
8 #include <assert.h>
9 #include <cstring>
10 #include <iostream>
11
12 #ifdef NDEBUG
13
14 #define ASSERT( expr ) \
15 if (false); \
16 else \
17 struct local_t \
18 { \
19 local_t( const asserter_t & ) {} \
20 } local_obj = asserter_t(false)
21
22 // asserter_t
23 class asserter_t
24 {
25 public:
26 template<class T> const asserter_t operator()(const T &) const { return asserter_t(); }
27 };
28
29 #else
30
31 #define SMART_ASSERT_A(x) SMART_ASSERT_OP(x, B)
32 #define SMART_ASSERT_B(x) SMART_ASSERT_OP(x, A)
33 #define SMART_ASSERT_OP(x, next) SMART_ASSERT_A.print_current_val((x), #x).SMART_ASSERT_ ## next
34
35 #ifndef TARGET_TEST
36 #define TARGET_TEST 0
37 #endif
38
39 #define ASSERT( expr ) \
40 if (!TARGET_TEST && (expr)); \
41 else \
42 struct local_t \
43 { \
44 local_t( const asserter_t & o ) \
45 { \
46 if( !(o.pass()) ) \
47 assert(false); \
48 } \
49 } \
50 local_obj = \
51 asserter_t( expr ) \
52 .print_message( __FILE__, __LINE__, __FUNCTION__, #expr ) \
53 .archive_result( __FILE__, __LINE__, __FUNCTION__, #expr ) \
54 .SMART_ASSERT_A
55
56 // asserter_t
57 struct asserter_t final
58 {
59 asserter_t(bool);
60
61 bool pass() const;
62
63 const asserter_t & print_message(
64 const char * file,
65 int line,
66 const char * function,
67 const char * = "" ) const;
68
69 const asserter_t & archive_result(
70 const char * file,
71 int line,
72 const char * function,
73 const char * = "" ) const;
74
75 template<class U> const asserter_t & print_current_val(const U &, const char*) const;
76
77 asserter_t & SMART_ASSERT_A;
78 asserter_t & SMART_ASSERT_B;
79
80 private:
81 const bool m_value;
82 };
83
84 #include "asserter.hxx"
85
86 #endif // NDEBUG
87
88 #endif // ASSERT_H_9879879hkjh
File asserter/src/asserter.hxx added (mode: 100755) (index 0000000..c6a05f5)
1 // /////////////////////////////////////////////////////////////////////////////////////////////
2 // // asserter_t
3 // /////////////////////////////////////////////////////////////////////////////////////////////
4 template<class U> const asserter_t & asserter_t::print_current_val(const U & value, const char * message) const
5 {
6 std::cout << message << ": " << value << std::endl;
7 return * this;
8 }
File asserter/src/test.h added (mode: 100644) (index 0000000..d8917a4)
1 #ifndef TEST_H_3240OIJOOREOGGO
2 #define TEST_H_3240OIJOOREOGGO
3
4 #include <iostream>
5
6 #include "asserter.h"
7
8 #define FOOTER std::cout << __FUNCTION__ << " passed" << std::endl;
9
10 #endif // TEST_H_3240OIJOOREOGGO
File asserter/test/lib/asserter added (mode: 120000) (index 0000000..c25bddb)
1 ../..
File asserter/test/src/check_assert.cpp added (mode: 100644) (index 0000000..f56fbc2)
1 #include <string>
2 #include <exception>
3
4 #include <tmp/src/test.h>
5
6 int main(int argc, const char * argv[])
7 {
8 using namespace std;
9 string a( "hello" );
10
11 ASSERT( !a.empty() )( a )( a.size() );
12
13 return 0;
14 }
File asserter/test/test.js added (mode: 100755) (index 0000000..ecc54e6)
1 #!/usr/bin/env node
2
3 'use strict';
4
5 var test = require( 'tape' )
6 , fs = require( 'fs' )
7 , cp = require( 'child_process' )
8 , path = require( 'path' )
9 , Expector = require( 'expector' ).SeqExpector;
10
11 test( 'asserter', function(t) {
12 var controller = new Expector(t)
13 , resultPath = path.join( __dirname, 'tmp/result.json' );
14
15 controller
16 .expect( 'not exits' )
17 .expect( 'exits' )
18 .expect( 0 );
19
20 fs.unlink( resultPath, function(err) {
21 tryOpen();
22 crimp([ './test.json', '-g' ], controller, tryOpen );
23 } );
24
25 function crimp(args, controller, cb) {
26
27 var child = cp
28 .spawn( 'crimp',
29 args,
30 { stdio: 'pipe', cwd: __dirname } )
31 .on( 'exit', function(code) {
32
33 if (typeof cb !== 'undefined') {
34 cb();
35 }
36 controller.emit( code );
37 controller.check();
38 })
39 .on( 'error', (error) => {
40 console.log( 'error:', error );
41 });
42
43 return child;
44 }
45
46 function tryOpen() {
47 try {
48 fs.statSync( resultPath );
49 controller.emit( "exits" );
50 }
51 catch(err) {
52 controller.emit( "not exits" );
53 }
54 }
55
56 });
File asserter/test/test.json added (mode: 100644) (index 0000000..3e18194)
1 {
2 "sources": [
3 "src/check_assert.cpp"
4 ]
5 }
File index.js changed (mode: 100755) (index 63c5640..f482bc0)
... ... const shell = require( 'shelljs' ),
6 6 deepmerge = require('deepmerge'), deepmerge = require('deepmerge'),
7 7 [,,defPath, ... otherArgs] = process.argv; [,,defPath, ... otherArgs] = process.argv;
8 8
9 readDef(defPath).then( obj => console.log('\n' + JSON.stringify(obj, null, 2)) );
9 readDef(defPath)
10 .then( obj => console.log(obj.sources.join(' ')));
10 11 /* /*
11 12 const def = JSON.parse(fs.readFileSync(defPath, 'utf8')); const def = JSON.parse(fs.readFileSync(defPath, 'utf8'));
12 13
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/mucbuc/ccargs

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/mucbuc/ccargs

Clone this repository using git:
git clone git://git.rocketgit.com/user/mucbuc/ccargs

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main