use P4::test; use P4::TM { DATA_DIR => 'self' }; use Data::Dumper; use File::Copy; use Text::Diff; use File::Copy::Recursive 'dircopy'; P4::TM::add_mask_func sub { s/manuals\/v[0-9]{2}\.[0-9]{1}\/extensions/manuals\/vYY.H\/extensions/g; $_ }; `p4 configure set server.extensions.allow.unsigned=1`; # todo: Unicode my $u = $ENV{ P4USER }; dircopy $script_abspath =~ s/\.t$//r . '/*', 'SpecFormatterExt'; cp 'foo/manifest.lua', 'SpecFormatterExt'; copy "$script_home_abspath/inspect.lua", 'SpecFormatterExt'; `p4 user -o sampleExtensionsUser | p4 user -i -f`; tm `p4 extension --package SpecFormatterExt`; tm `p4 extension --install SpecFormatterExt.p4-extension`; tm `p4 extension --install SpecFormatterExt.p4-extension -y`; tm `p4 extension --configure ExampleInc::SpecFormatterExt -o | p4 extension --configure ExampleInc::SpecFormatterExt -i`; `p4 depot -o $_ | p4 depot -i` for qw / toped d deeeeepooooot /; $stdin = << 'EOF' Branch: branch-simple Owner: user Description: Created by user. Options: unlocked View: //toped/... //toped/... EOF ; `p4 branch -i`; $stdin = << 'EOF' Branch: branch-simple1 Owner: user Description: Created by user. Options: unlocked View: //depot/... //depot/... //d/... //d/... EOF ; `p4 branch -i`; $stdin = << 'EOF' Branch: branch-simple2 Owner: user Description: Created by user. Options: unlocked View: //depot/... //depot/... //d/... //d/... //deeeeepooooot/... //deeeeepooooot/... EOF ; `p4 branch -i`; $stdin = << 'EOF' Client: client-simple Owner: user Description: Created by user. Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-simple/... EOF ; `p4 client -i`; $stdin = << 'EOF' Client: client-plus Owner: user Description: Created by user. Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-plus/... +//d/... //client-plus/... //deeeeepooooot/... //client-plus/deeeeepooooot/... EOF ; `p4 client -i`; $stdin = << 'EOF' Client: client-quotes Owner: user Description: Created by user. Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-quotes/... "//depot/a file" "//client-quotes/a file" EOF ; `p4 client -i`; $stdin = << 'EOF' Client: client-all Owner: user Description: Created by user. Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-all/... "//depot/a file" "//client-all/a file" +//d/... //client-all/... "&//depot/a file" "//client-all/a file two" -//d/foo //client-all/foo //toped/a/b/c/... //client-all/toped/a/b/c/... "-//depot/b file" "//client-all/b file" //toped/aaaaaaaaaaa //client-all/aaaaaaaaaaaaa "+//depot/c file" "//client-all/c file" EOF ; `p4 client -i`; $stdin = << 'EOF' Client: client-big Owner: user Description: Created by user. Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: EOF ; #$stdin .= "\n //depot/$_ //client-big/$_" for 0 .. 5_000; `p4 client -i`; $stdin = "Protections:\n" . << "EOF" list user * * //... =branch user abc 127.0.0.1 "//depot/a file" ## same-line comment super user $P4CONFIG{P4USER} * //... write group abcdefg ::1 "-//depot/another spacey file" open user ** ** "+//depot/a file" read user * * //... admin group "g ads" "s t a r" "-p a t h" super user nofmt * //... ## trailing comment EOF ; `p4 protect -i`; # todo: try putting in a bad value # todo: try one with stripHeaderComment enabled sub mkCfg { our $type = shift; $stdin = `p4 extension --configure ExampleInc::SpecFormatterExt --name SpecFormatterExt-$type -o`; $stdin =~ s#The form type to format: branch/client/label/protect/triggers##g; $stdin =~ s/formType:.*/formType: $type/g; $stdin =~ s/users:.*/users:$u/g; $stdin =~ s/Space-separated list of which users get formatted specs//g; tm `p4 extension --configure ExampleInc::SpecFormatterExt --name SpecFormatterExt-$type -i`; } mkCfg $_ for qw / branch client label protect triggers /; sub noc($) { $_[ 0 ] =~ s/^#.*//grm =~ s/^\s*\R+//mgr } sub cmpSpec { my ( $spec, $arg ) = $_[ 0 ] =~ /(\w+)(?:-(\w+))?/; $arg //= ''; $arg = "$spec-$arg" if $arg; my $nfmt = `p4 -u nofmt $spec -o $arg` =~ s/Owner:.*/Owner: OWNERMASK/gr =~ s/Created by .*/Created by OWNERMASK/gr; my $yfmt = `p4 $spec -o $arg` =~ s/Owner:.*/Owner: OWNERMASK/gr =~ s/Created by .*/Created by OWNERMASK/gr; my $nfmt_ns = $nfmt =~ s/\s*//gr; my $yfmt_ns = $yfmt =~ s/\s*//gr; noc $yfmt, diff \ $nfmt_ns, \ $yfmt_ns, { STYLE => 'OldStyle' } } tm `p4 branches`; tm `p4 clients`; tm `p4 labels`; tm noc `p4 -u nofmt triggers -o`; tm noc `p4 -u nofmt protect -o`; tm cmpSpec 'protect'; tm cmpSpec 'branch-simple'; tm cmpSpec 'branch-simple1'; tm cmpSpec 'branch-simple2'; tm noc `p4 -u nofmt branch -o branch-simple2`; tm cmpSpec 'client-simple'; tm cmpSpec 'client-plus'; tm cmpSpec 'client-big'; tm cmpSpec 'client-quotes'; tm noc `p4 -u nofmt client -o client-quotes`; tm noc `p4 -u nofmt client -o client-all`; tm cmpSpec 'client-all'; #use Data::Dumper; #diag 'stdout: '.Dumper $server->getSTDOUT; #diag 'stderr: '.Dumper $server->getSTDERR; __DATA__ [[23,24,25,26,172,'172.1','172.2','172.3','172.4',195,196,197,198,200,201,203,204,205,206,208,209,210,211,212,214,215], [ 'p4 extension --package SpecFormatterExt', 'Extension packaged successfully. ', 0, 'p4 extension --install SpecFormatterExt.p4-extension', ' Would install Extension \'ExampleInc::SpecFormatterExt\' Version: \'2019.1\' UUID: CFA3E352-1440-4799-80FF-62D2CB16F6EE Developer: Perforce Software Inc. Description: [Example Extension, sample code] Pretty-print specs. Align the content of branch, client, label, protect and trigger forms into evenly-spaced columns. E.g.: Protections: list user * * //... =branch user abc 127.0.0.1 "//depot/a file" ## same-line comment super user user * //... write group abcdefg ::1 "-//depot/another spacey file" open user ** ** "+//depot/a file" read user * * //... admin group g_ads s_t_a_r "-p a t h" super user nofmt * //... ## trailing comment Becomes Protections: list user * * //... =branch user abc 127.0.0.1 "//depot/a file" ## same-line comment super user user * //... write group abcdefg ::1 "-//depot/another spacey file" open user ** ** "+//depot/a file" read user * * //... admin group g_ads s_t_a_r "-p a t h" super user nofmt * //... ## trailing comment License: BSD Homepage URL: https://swarm.workshop.perforce.com/files/guest/perforce_software/extensions/2019-1 Compatible products: p4d This was report mode. Use -y to perform the operation. ', 0, 'p4 extension --install SpecFormatterExt.p4-extension -y', ' Extension \'ExampleInc::SpecFormatterExt\' version \'2019.1\' installed successfully. Perform the following steps to turn on the Extension: # Create a global configuration if one doesn\'t already exist. p4 extension --configure ExampleInc::SpecFormatterExt # Create an instance configuration to enable the Extension. p4 extension --configure ExampleInc::SpecFormatterExt --name ExampleInc::SpecFormatterExt-instanceName For more information, visit: https://www.perforce.com/manuals/vYY.H/extensions/Content/Extensions/Home-extensions.html ', 0, 'p4 extension --configure ExampleInc::SpecFormatterExt -o | p4 extension --configure ExampleInc::SpecFormatterExt -i', 'Extension config SpecFormatterExt saved. ', 0, 'p4 extension --configure ExampleInc::SpecFormatterExt --name SpecFormatterExt-branch -i', 'Extension config SpecFormatterExt-branch saved. ', 0, 'p4 extension --configure ExampleInc::SpecFormatterExt --name SpecFormatterExt-client -i', 'Extension config SpecFormatterExt-client saved. ', 0, 'p4 extension --configure ExampleInc::SpecFormatterExt --name SpecFormatterExt-label -i', 'Extension config SpecFormatterExt-label saved. ', 0, 'p4 extension --configure ExampleInc::SpecFormatterExt --name SpecFormatterExt-protect -i', 'Extension config SpecFormatterExt-protect saved. ', 0, 'p4 extension --configure ExampleInc::SpecFormatterExt --name SpecFormatterExt-triggers -i', 'Extension config SpecFormatterExt-triggers saved. ', 0, 'p4 branches', ' Branch branch-simple */*/* \'Created * Branch branch-simple1 */*/* \'Created * Branch branch-simple2 */*/* \'Created * ', 0, 'p4 clients', ' Client client-all */*/* root nosuch \'Created * Client client-big */*/* root nosuch \'Created * Client client-plus */*/* root nosuch \'Created * Client client-quotes */*/* root nosuch \'Created * Client client-simple */*/* root nosuch \'Created * ', 0, 'p4 labels', '', 0, 'noc `p4 -u nofmt triggers -o', 'Triggers: ', 0, 'noc `p4 -u nofmt protect -o', ' Update: */*/* *:*:* Protections: list user * * //... =branch user abc 127.0.0.1 "//depot/a file" ## same-line comment super user user * //... write group abcdefg ::1 "-//depot/another spacey file" open user ** ** "+//depot/a file" read user * * //... admin group g_ads s_t_a_r "-p a t h" super user nofmt * //... ## trailing comment ', 0, 'cmpSpec \'protect\'', ' Update: */*/* *:*:* Protections: list user * * //... =branch user abc 127.0.0.1 "//depot/a file" ## same-line comment super user user * //... write group abcdefg ::1 "-//depot/another spacey file" open user ** ** "+//depot/a file" read user * * //... admin group g_ads s_t_a_r "-p a t h" super user nofmt * //... ## trailing comment ', 0, 'cmpSpec \'branch-simple\'', ' Branch: branch-simple Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Options: unlocked View: //toped/... //toped/... ', 0, 'cmpSpec \'branch-simple1\'', ' Branch: branch-simple1 Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Options: unlocked View: //depot/... //depot/... //d/... //d/... ', 0, 'cmpSpec \'branch-simple2\'', ' Branch: branch-simple2 Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Options: unlocked View: //depot/... //depot/... //d/... //d/... //deeeeepooooot/... //deeeeepooooot/... ', 0, 'noc `p4 -u nofmt branch -o branch-simple2', ' Branch: branch-simple2 Update: */*/* *:*:* Access: */*/* *:*:* Owner: user Description: Created by user. Options: unlocked View: //depot/... //depot/... //d/... //d/... //deeeeepooooot/... //deeeeepooooot/... ', 0, 'cmpSpec \'client-simple\'', ' Client: client-simple Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-simple/... ', 0, 'cmpSpec \'client-plus\'', ' Client: client-plus Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-plus/... +//d/... //client-plus/... //deeeeepooooot/... //client-plus/deeeeepooooot/... ', 0, 'cmpSpec \'client-big\'', ' Client: client-big Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local ', 0, 'cmpSpec \'client-quotes\'', ' Client: client-quotes Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-quotes/... "//depot/a file" "//client-quotes/a file" ', 0, 'noc `p4 -u nofmt client -o client-quotes', ' Client: client-quotes Update: */*/* *:*:* Access: */*/* *:*:* Owner: user Description: Created by user. Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-quotes/... "//depot/a file" "//client-quotes/a file" ', 0, 'noc `p4 -u nofmt client -o client-all', ' Client: client-all Update: */*/* *:*:* Access: */*/* *:*:* Owner: user Description: Created by user. Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-all/... "//depot/a file" "//client-all/a file" +//d/... //client-all/... "&//depot/a file" "//client-all/a file two" -//d/foo //client-all/foo //toped/a/b/c/... //client-all/toped/a/b/c/... "-//depot/b file" "//client-all/b file" //toped/aaaaaaaaaaa //client-all/aaaaaaaaaaaaa "+//depot/c file" "//client-all/c file" ', 0, 'cmpSpec \'client-all\'', ' Client: client-all Update: */*/* *:*:* Access: */*/* *:*:* Owner: OWNERMASK Description: Created by OWNERMASK Root: nosuch Options: noallwrite noclobber nocompress unlocked nomodtime normdir noaltsync SubmitOptions: submitunchanged LineEnd: local View: //depot/... //client-all/... "//depot/a file" "//client-all/a file" +//d/... //client-all/... "&//depot/a file" "//client-all/a file two" -//d/foo //client-all/foo //toped/a/b/c/... //client-all/toped/a/b/c/... "-//depot/b file" "//client-all/b file" //toped/aaaaaaaaaaa //client-all/aaaaaaaaaaaaa "+//depot/c file" "//client-all/c file" ', 0 ] ]
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 30809 | C. Thomas Tyler |
Code drop with newer versions of Extensions. Thanks to @jason_gibon. #review-30810 @jabson_gibson |
||
#1 | 30808 | C. Thomas Tyler |
Promoted from 2019.1/... to main/... |
||
//guest/perforce_software/extensions/2019.1/spec_pretty_printer.t | |||||
#1 | 25601 | Jason Gibson |
Import example Extensions. p19.1@1797741 |